2 main routine for swfcombine(1), a tool for merging .swf-files.
4 Part of the swftools package.
6 Copyright (c) 2001,2002,2003 Matthias Kramm <kramm@quiss.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
25 #include "../lib/rfxswf.h"
26 #include "../lib/args.h"
27 #include "../lib/log.h"
28 #include "../config.h"
58 struct config_t config;
60 char * master_filename = 0;
61 char * master_name = 0;
62 char * slave_filename[128];
63 char * slave_name[128];
66 float slave_scalex[128];
67 float slave_scaley[128];
68 char slave_isframe[128];
71 char * outputname = "output.swf";
73 int args_callback_option(char*name,char*val) {
79 else if(!strcmp(name,"l"))
84 else if (!strcmp(name, "o"))
89 else if (!strcmp(name, "v"))
94 else if (!strcmp(name, "a"))
99 else if (!strcmp(name, "A"))
101 config.alloctest = 1;
104 else if (!strcmp(name, "x"))
106 config.movex = atoi(val);
109 else if (!strcmp(name, "y"))
111 config.movey = atoi(val);
114 else if (!strcmp(name, "m"))
119 else if (!strcmp(name, "f"))
124 else if (!strcmp(name, "d"))
129 else if (!strcmp(name, "z"))
134 else if (!strcmp(name, "r"))
137 float rate = atof(val);
138 if ((rate < 1.0/256) ||(rate >= 256.0)) {
139 fprintf(stderr, "Error: You must specify a valid framerate between 1/256 and 255.\n");
142 config.framerate = (int)(rate*256);
145 else if (!strcmp(name, "X"))
147 config.sizex = atoi(val)*20;
151 else if (!strcmp(name, "Y"))
153 config.sizey = atoi(val)*20;
157 else if (!strcmp(name, "s"))
159 config.scalex = config.scaley = atoi(val)/100.0;
162 else if (!strcmp(name, "t") || !strcmp(name, "T"))
164 if(master_filename) {
165 fprintf(stderr, "error with arguments. Try --help.\n");
169 if(!strcmp(name,"T"))
171 master_filename = "__none__";
174 else if (!strcmp(name, "V"))
176 printf("swfcombine - part of %s %s\n", PACKAGE, VERSION);
181 fprintf(stderr, "Unknown option: -%s\n", name);
186 struct options_t options[] =
208 int args_callback_longoption(char*name,char*val) {
209 return args_long2shortoption(options, name, val);
212 int args_callback_command(char*name, char*val) {
213 char*myname = strdup(name);
215 filename = strchr(myname, '=');
220 // argument has no explicit name field. guess one from the file name
221 char*path = strrchr(myname, '/');
222 char*ext = strrchr(myname, '.');
223 if(!path) path = myname;
230 if(!master_filename) {
231 master_filename = filename;
232 master_name = myname;
233 config.mastermovex = config.movex;
234 config.mastermovey = config.movey;
235 config.masterscalex = config.scalex;
236 config.masterscaley = config.scaley;
237 config.movex = config.movey = 0;
238 config.scalex = config.scaley = 1.0;
240 msg("<verbose> slave entity %s (named \"%s\")\n", filename, myname);
242 slave_filename[numslaves] = filename;
243 slave_name[numslaves] = myname;
244 slave_movex[numslaves] = config.movex;
245 slave_movey[numslaves] = config.movey;
246 slave_scalex[numslaves] = config.scalex;
247 slave_scaley[numslaves] = config.scaley;
248 slave_isframe[numslaves] = config.isframe;
250 config.movex = config.movey = 0;
251 config.scalex = config.scaley = 1.0;
257 void args_callback_usage(char*name)
259 printf("Usage: %s [-rXYomlcv] [-f] masterfile [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
260 printf("OR: %s [-rXYomv] --stack[1] [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
261 printf("OR: %s [-rXYov] --cat [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
262 printf("OR: %s [-rXYomlcv] --dummy [-xys] [file]\n", name);
264 printf("-o outputfile --output explicitly specify output file. (otherwise, output.swf will be used)\n");
265 printf("-t --stack place each slave in a seperate frame (no master movie)\n");
266 printf("-T --stack1 place each slave in the first frame (no master movie)\n");
267 printf("-m --merge Don't store the slaves in Sprites/MovieClips\n");
268 printf("-a --cat concatenate all slave files (no master movie)\n");
269 printf("-l --overlay Don't remove any master objects, only overlay new objects\n");
270 printf("-c --clip Clip the slave objects by the corresponding master objects\n");
271 printf("-v --verbose Use more than one -v for greater effect \n");
272 printf("-d --dummy Don't require slave objects \n");
273 printf("-f --frame The following identifier is a frame or framelabel, not an id or objectname\n");
274 printf("-x xpos --movex x Adjust position of slave by xpos twips (1/20 pixel)\n");
275 printf("-y ypos --movey y Adjust position of slave by ypos twips (1/20 pixel)\n");
276 printf("-s scale --scale Adjust size of slave by scale%\n");
277 printf("-r framerate --rate Set movie framerate (frames/sec)\n");
278 printf("-X width --width Force movie width to scale (default: use master width (not with -t))\n");
279 printf("-Y height --height Force movie height to scale (default: use master height (not with -t))\n");
280 printf("-z zlib --zlib Enable Flash 6 (MX) Zlib Compression\n");
283 static void makestackmaster(SWF*swf)
292 memset(&box, 0, sizeof(box));
294 /* scan all slaves for bounding box */
295 for(t=numslaves-1;t>=0;t--)
299 int fi=open(slave_filename[t],O_RDONLY|O_BINARY);
301 if(fi<0 || swf_ReadSWF(fi, &head)<0) {
302 msg("<fatal> Couldn't open/read %s.", slave_filename[t]);
306 msg("<verbose> File %s has bounding box %d:%d:%d:%d\n",
308 head.movieSize.xmin, head.movieSize.ymin,
309 head.movieSize.xmax, head.movieSize.ymax);
313 if(tag->id == ST_SETBACKGROUNDCOLOR && tag->len>=3) {
314 rgb.r = tag->data[0];
315 rgb.g = tag->data[1];
316 rgb.b = tag->data[2];
320 frameRate = head.frameRate;
321 if(head.fileVersion > fileversion)
322 fileversion = head.fileVersion;
324 box = head.movieSize;
326 if(head.movieSize.xmin < box.xmin)
327 box.xmin = head.movieSize.xmin;
328 if(head.movieSize.ymin < box.ymin)
329 box.ymin = head.movieSize.ymin;
330 if(head.movieSize.xmax > box.xmax)
331 box.xmax = head.movieSize.xmax;
332 if(head.movieSize.ymax > box.ymax)
333 box.ymax = head.movieSize.ymax;
335 msg("<verbose> New master bounding box is %d:%d:%d:%d\n",
341 memset(swf, 0, sizeof(SWF));
342 swf->fileVersion = fileversion;
343 swf->movieSize = box;
344 swf->frameRate = frameRate;
346 swf->firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
348 swf_SetRGB(tag, &rgb);
350 for(t=0;t<numslaves;t++)
353 sprintf(buf, "Frame%02d", t);
354 slave_name[t] = strdup(buf);
356 tag = swf_InsertTag(tag, ST_DEFINESPRITE);
357 swf_SetU16(tag, t+1);
359 tag = swf_InsertTag(tag, ST_END);
360 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
361 swf_ObjectPlace(tag, t+1, 1+t,0,0, slave_name[t]);
363 if(!config.stack1 || t == numslaves-1) {
364 tag = swf_InsertTag(tag, ST_SHOWFRAME);
369 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
370 swf_SetU16(tag, 1+t);
373 tag = swf_InsertTag(tag, ST_END);
374 msg("<verbose> temporary SWF created");
377 static char* slavename = 0;
378 static int slaveid = -1;
379 static int slaveframe = -1;
380 static char masterbitmap[65536];
382 #define FLAGS_WRITEDEFINES 1
383 #define FLAGS_WRITENONDEFINES 2
384 #define FLAGS_WRITESPRITE 4
385 #define FLAGS_WRITESLAVE 8
387 int get_free_id(char*bitmap)
398 void jpeg_assert(SWF*master, SWF*slave)
400 /* TODO: if there's a jpegtable found, store it
401 and handle it together with the flash file
404 /* check that master and slave don't have both
405 jpegtables (which would be fatal) */
407 TAG *mpos=0, *spos=0;
410 mtag = master->firstTag;
411 stag = slave->firstTag;
414 if(mtag->id == ST_JPEGTABLES)
420 if(stag->id == ST_JPEGTABLES)
426 if(spos->len == mpos->len &&
427 !memcmp(spos->data, mpos->data, mpos->len))
429 // ok, both have jpegtables, but they're identical.
430 // delete one and don't throw an error
436 msg("<error> Master and slave have incompatible JPEGTABLES.");
440 TAG* write_sprite_defines(TAG*tag, SWF*sprite)
442 TAG*rtag = sprite->firstTag;
443 while(rtag && rtag->id!=ST_END) {
444 if(!swf_isAllowedSpriteTag(rtag)) {
445 msg("<debug> processing sprite tag %02x", tag->id);
446 if(swf_isDefiningTag(rtag))
448 msg("<debug> [sprite defs] write tag %02x (%d bytes in body)",
450 tag = swf_InsertTag(tag, rtag->id);
451 swf_SetBlock(tag, rtag->data, rtag->len);
453 else if(swf_isPseudoDefiningTag(rtag))
455 msg("<debug> [sprite defs] write tag %02x (%d bytes in body)",
457 tag = swf_InsertTag(tag, rtag->id);
458 swf_SetBlock(tag, rtag->data, rtag->len);
464 /* if we get here, jpeg_assert has already run,
465 ensuring this is the only one of it's kind,
466 so we may safely write it out */
467 tag = swf_InsertTag(tag, rtag->id);
468 swf_SetBlock(tag, rtag->data, rtag->len);
470 case ST_EXPORTASSETS:
471 msg("<debug> deliberately ignoring EXPORTASSETS tag");
473 case ST_ENABLEDEBUGGER:
474 msg("<debug> deliberately ignoring ENABLEDEBUGGER tag");
476 case ST_SETBACKGROUNDCOLOR:
477 msg("<debug> deliberately ignoring BACKGROUNDCOLOR tag");
482 msg("<notice> found tag %d. This is a Generator template, isn't it?", tag->id);
485 msg("<notice> funny tag: %d is neither defining nor sprite", tag->id);
494 void changedepth(TAG*tag, int add)
496 /* fucking byteorders */
497 if(tag->id == ST_PLACEOBJECT)
498 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
499 if(tag->id == ST_PLACEOBJECT2)
500 PUT16(&tag->data[1],GET16(&tag->data[1])+add);
501 if(tag->id == ST_REMOVEOBJECT)
502 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
503 if(tag->id == ST_REMOVEOBJECT2)
504 PUT16(&tag->data[0],GET16(&tag->data[0])+add);
507 void matrix_adjust(MATRIX*m, int movex, int movey, float scalex, float scaley, int scalepos)
509 m->sx = (int)(m->sx*scalex);
510 m->sy = (int)(m->sy*scaley);
511 m->r1 = (int)(m->r1*scalex);
512 m->r0 = (int)(m->r0*scaley);
521 void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, float scaley, int scalepos)
523 if(movex || movey || scalex != 1 || scaley != 1)
527 case ST_PLACEOBJECT2: {
530 swf_GetMatrix(0, &m);
534 flags = swf_GetU8(tag);
535 swf_SetU8(output, flags|4);
536 swf_SetU16(output, swf_GetU16(tag)); //depth
539 swf_SetU16(output, swf_GetU16(tag)); //id
543 swf_GetMatrix(tag, &m);
545 swf_GetMatrix(0, &m);
547 matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
548 swf_SetMatrix(output, &m);
550 //swf_ResetReadBits(tag);
551 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
554 case ST_PLACEOBJECT: {
556 swf_SetU16(output, swf_GetU16(tag)); //id
557 swf_SetU16(output, swf_GetU16(tag)); //depth
559 swf_GetMatrix(tag, &m);
560 matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
561 swf_SetMatrix(output, &m);
563 //swf_ResetReadBits(tag);
564 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
568 swf_SetBlock(output, tag->data, tag->len);
573 swf_SetBlock(output, tag->data, tag->len);
577 TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
579 TAG* definespritetag;
583 definespritetag = tag = swf_InsertTag(tag, ST_DEFINESPRITE);
584 swf_SetU16(tag, spriteid);
585 swf_SetU16(tag, sprite->frameCount);
586 msg ("<notice> sprite id is %d", spriteid);
588 tmp = sprite->frameCount;
589 msg("<debug> %d frames to go",tmp);
592 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
593 swf_SetU8(tag, 2+64); //flags: character+clipdepth
594 swf_SetU16(tag, 0); //depth
595 swf_SetU16(tag, replaceddefine); //id
596 swf_SetU16(tag, 65535); //clipdepth
599 if(config.overlay && !config.isframe) {
600 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
601 swf_SetU8(tag, 2); //flags: character
602 swf_SetU16(tag, 1); //depth
603 swf_SetU16(tag, replaceddefine); //id
606 rtag = sprite->firstTag;
607 while(rtag && rtag->id!=ST_END)
609 if (swf_isAllowedSpriteTag(rtag)) {
611 msg("<debug> [sprite main] write tag %02x (%d bytes in body)",
612 rtag->id, rtag->len);
613 tag = swf_InsertTag(tag, rtag->id);
614 write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley, 0);
616 changedepth(tag, +2);
618 if(tag->id == ST_SHOWFRAME)
621 msg("<debug> %d frames to go",tmp);
626 tag = swf_InsertTag(tag, ST_END);
630 static char tag_ok_for_slave(int id)
632 if(id == ST_SETBACKGROUNDCOLOR)
637 TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefine, int flags)
642 int slavewritten = 0;
644 TAG* rtag = master->firstTag;
645 TAG* stag = slave->firstTag;
647 while(rtag && rtag->id!=ST_END)
649 if(rtag->id == ST_SHOWFRAME && outputslave)
651 while(stag && stag->id!=ST_END) {
652 if(stag->id == ST_SHOWFRAME) {
657 if(tag_ok_for_slave(stag->id)) {
658 tag = swf_InsertTag(tag, stag->id);
659 swf_SetBlock(tag, stag->data, stag->len);
664 if(rtag->id == ST_SHOWFRAME)
669 if(swf_isDefiningTag(rtag) && (flags&FLAGS_WRITEDEFINES))
671 msg("<debug> [master] write tag %02x (%d bytes in body)",
672 rtag->id, rtag->len);
673 if(swf_GetDefineID(rtag) == spriteid && !config.isframe)
677 tag = swf_InsertTag(tag, rtag->id);
678 swf_SetBlock(tag, rtag->data, rtag->len);
679 swf_SetDefineID(tag, replaceddefine);
681 /* don't write this tag */
682 msg("<verbose> replacing tag %d id %d with sprite", rtag->id
686 if(flags&FLAGS_WRITESPRITE)
688 tag = write_sprite_defines(tag, slave);
689 tag = write_sprite(tag, slave, spriteid, replaceddefine);
691 if(flags&FLAGS_WRITESLAVE)
696 tag = swf_InsertTag(tag, rtag->id);
697 swf_SetBlock(tag, rtag->data, rtag->len);
700 if(frame == slaveframe)
702 if(flags&FLAGS_WRITESLAVE) {
706 if((flags&FLAGS_WRITESPRITE) && !slavewritten)
708 int id = get_free_id(masterbitmap);
711 msg("<fatal> Can't combine --clip and --frame");
714 tag = write_sprite_defines(tag, slave);
715 tag = write_sprite(tag, slave, id, -1);
717 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
718 swf_SetU8(tag, 2); //flags: id
719 swf_SetU16(tag, depth);
725 if(!swf_isDefiningTag(rtag) && (flags&FLAGS_WRITENONDEFINES))
730 case ST_PLACEOBJECT2:
731 if(frame == slaveframe && !config.overlay)
733 case ST_REMOVEOBJECT:
734 /* place/removetags for the object we replaced
735 should be discarded, too, as the object to insert
738 if(spriteid>=0 && swf_GetPlaceID(rtag) == spriteid &&
739 !config.isframe && config.merge)
742 case ST_REMOVEOBJECT2:
746 msg("<debug> [master] write tag %02x (%d bytes in body)",
747 rtag->id, rtag->len);
748 tag = swf_InsertTag(tag, rtag->id);
749 write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley, 1);
756 while(stag && stag->id!=ST_END)
758 if(tag_ok_for_slave(stag->id)) {
759 tag = swf_InsertTag(tag, stag->id);
760 swf_SetBlock(tag, stag->data, stag->len);
764 if(!slavewritten && config.isframe && (flags&(FLAGS_WRITESLAVE|FLAGS_WRITESPRITE)))
767 msg("<warning> Frame %d doesn't exist in file. No substitution will occur",
770 msg("<warning> Frame \"%s\" doesn't exist in file. No substitution will occur",
773 tag = swf_InsertTag(tag, ST_END);
777 void adjustheader(SWF*swf)
780 swf->frameRate = config.framerate;
781 if(config.hassizex) {
782 swf->movieSize.xmax =
783 swf->movieSize.xmin + config.sizex;
785 if(config.hassizey) {
786 swf->movieSize.ymax =
787 swf->movieSize.ymin + config.sizey;
791 void catcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
798 msg("<fatal> Can't combine --cat and --frame");
802 tag = master->firstTag;
805 if(swf_isDefiningTag(tag)) {
806 int defineid = swf_GetDefineID(tag);
807 msg("<debug> tagid %02x defines object %d", tag->id, defineid);
808 masterbitmap[defineid] = 1;
813 swf_Relocate(slave, masterbitmap);
814 jpeg_assert(master, slave);
816 memcpy(newswf, master, sizeof(SWF));
817 adjustheader(newswf);
819 tag = newswf->firstTag = swf_InsertTag(0, ST_REFLEX); // to be removed later
821 depths = malloc(65536);
823 msg("<fatal> Couldn't allocate %d bytes of memory", 65536);
826 memset(depths, 0, 65536);
827 mtag = master->firstTag;
828 while(mtag && mtag->id!=ST_END)
832 msg("<debug> [master] write tag %02x (%d bytes in body)",
833 mtag->id, mtag->len);
835 case ST_PLACEOBJECT2:
837 case ST_PLACEOBJECT: {
838 depth = swf_GetDepth(mtag);
842 case ST_REMOVEOBJECT: {
843 depth = swf_GetDepth(mtag);
847 case ST_REMOVEOBJECT2: {
848 depth = swf_GetDepth(mtag);
853 tag = swf_InsertTag(tag, mtag->id);
854 swf_SetBlock(tag, mtag->data, mtag->len);
864 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
869 stag = slave->firstTag;
870 while(stag && stag->id!=ST_END)
872 msg("<debug> [slave] write tag %02x (%d bytes in body)",
873 stag->id, stag->len);
874 tag = swf_InsertTag(tag, stag->id);
875 swf_SetBlock(tag, stag->data, stag->len);
878 tag = swf_InsertTag(tag, ST_END);
880 tag = newswf->firstTag;
881 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
885 void normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
888 int replaceddefine = -1;
891 TAG * tag = master->firstTag;
896 if(swf_isDefiningTag(tag)) {
897 int defineid = swf_GetDefineID(tag);
898 msg("<debug> tagid %02x defines object %d", tag->id, defineid);
899 masterbitmap[defineid] = 1;
900 if (!slavename && defineid==slaveid) {
903 msg("<notice> Slave file attached to object %d.", defineid);
906 } else if(tag->id == ST_PLACEOBJECT2) {
907 char * name = swf_GetName(tag);
908 int id = swf_GetPlaceID(tag);
911 msg("<verbose> tagid %02x places object %d named \"%s\"", tag->id, id, name);
913 msg("<verbose> tagid %02x places object %d (no name)", tag->id, id);
915 if (name && slavename && !strcmp(name,slavename)) {
918 msg("<notice> Slave file attached to named object %s (%d).", name, id);
921 } else if(tag->id == ST_SHOWFRAME) {
922 if(slaveframe>=0 && frame==slaveframe) {
923 msg("<notice> Slave file attached to frame %d.", frame);
926 } else if(tag->id == ST_FRAMELABEL) {
927 char * name = tag->data;
928 if(name && slavename && config.isframe && !strcmp(name, slavename)) {
930 msg("<notice> Slave file attached to frame %d (%s).", frame, name);
936 if (spriteid<0 && !config.isframe) {
938 if(strcmp(slavename,"!!dummy!!"))
939 msg("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
942 msg("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
943 spriteid = get_free_id(masterbitmap);
946 swf_Relocate (slave, masterbitmap);
947 jpeg_assert(slave, master);
950 replaceddefine = get_free_id(masterbitmap);
954 memcpy(newswf, master, sizeof(SWF));
955 adjustheader(newswf);
957 newswf->firstTag = tag = swf_InsertTag(0, ST_REFLEX); // to be removed later
959 if (config.antistream) {
961 msg("<fatal> Can't combine --antistream and --merge");
963 tag = write_sprite_defines(tag, slave);
964 tag = write_sprite(tag, slave, spriteid, replaceddefine);
965 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITEDEFINES);
966 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITENONDEFINES);
969 tag = write_master(tag, master, slave, spriteid, replaceddefine,
970 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESLAVE );
972 tag = write_master(tag, master, slave, spriteid, replaceddefine,
973 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESPRITE );
976 tag = newswf->firstTag;
977 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
981 void combine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
983 slavename = slave_name;
990 if(slavename[0] == '#')
992 slaveid = atoi(&slavename[1]);
999 if(slavename && slavename[0]!='#' && (sscanf(slavename, "%d", &tmp) ==
1000 strlen(slavename))) {
1001 /* if the name the slave should replace
1002 consists only of digits and the -f
1003 option is given, it probably is not
1004 a frame name but a frame number.
1011 slaveframe = slaveid;
1014 /* if id wasn't given as either #number or number,
1015 the name is a frame label. BTW: The user wouldn't necessarily have
1016 needed to supply the -f option in this case */
1020 msg("<debug> move x (%d)", config.movex);
1021 msg("<debug> move y (%d)", config.movey);
1022 msg("<debug> scale x (%f)", config.scalex);
1023 msg("<debug> scale y (%f)", config.scaley);
1024 msg("<debug> master move x (%d)", config.mastermovex);
1025 msg("<debug> master move y (%d)", config.mastermovey);
1026 msg("<debug> master scale x (%f)", config.masterscalex);
1027 msg("<debug> master scale y (%f)", config.masterscaley);
1028 msg("<debug> is frame (%d)", config.isframe);
1030 memset(masterbitmap, 0, sizeof(masterbitmap));
1033 return catcombine(master, slave_name, slave, newswf);
1035 return normalcombine(master, slave_name, slave, newswf);
1038 int main(int argn, char *argv[])
1047 config.antistream = 0;
1048 config.alloctest = 0;
1052 config.loglevel = 2;
1055 config.scalex = 1.0;
1056 config.scaley = 1.0;
1059 config.masterscalex = 1.0;
1060 config.masterscaley = 1.0;
1061 config.mastermovex = 0;
1062 config.mastermovey = 0;
1063 config.hassizex = 0;
1064 config.hassizey = 0;
1065 config.framerate = 0;
1071 processargs(argn, argv);
1072 initLog(0,-1,0,0,-1,config.loglevel);
1074 if(config.merge && config.cat) {
1075 msg("<error> Can't combine --cat and --merge");
1080 if(config.overlay) {
1081 msg("<error> Can't combine -l and -t");
1085 msg("<error> Can't combine -c and -t");
1088 msg("<verbose> (stacking) %d files found\n", numslaves);
1090 makestackmaster(&master);
1094 msg("<verbose> master entity %s (named \"%s\")\n", master_filename, master_name);
1095 fi = open(master_filename, O_RDONLY|O_BINARY);
1097 msg("<fatal> Failed to open %s\n", master_filename);
1100 ret = swf_ReadSWF(fi, &master);
1102 msg("<fatal> Failed to read from %s\n", master_filename);
1105 msg("<debug> Read %d bytes from masterfile\n", ret);
1109 for(t=0;t<numslaves;t++) {
1110 msg("<verbose> slave entity(%d) %s (%s \"%s\")\n", t+1, slave_filename[t],
1111 slave_isframe[t]?"frame":"object", slave_name[t]);
1118 msg("<error> --dummy (-d) implies there are zero slave objects. You supplied %d.", numslaves);
1122 slave_filename[0] = "!!dummy!!";
1123 slave_name[0] = "!!dummy!!";
1124 slave_isframe[0] = 0;
1127 if (config.alloctest)
1129 char*bitmap = malloc(sizeof(char)*65536);
1130 memset(bitmap, 0, 65536*sizeof(char));
1131 memset(bitmap, 1, 101*sizeof(char));
1132 swf_Relocate(&master, bitmap);
1135 // makestackmaster(&newswf);
1142 msg("<error> You must have at least two objects.");
1144 msg("<error> You must have at least one slave entity.");
1147 for(t = 0; t < numslaves; t++)
1149 config.movex = slave_movex[t];
1150 config.movey = slave_movey[t];
1151 config.scalex = slave_scalex[t];
1152 config.scaley = slave_scaley[t];
1153 config.isframe = slave_isframe[t];
1155 msg("<notice> Combine [%s]%s and [%s]%s", master_name, master_filename,
1156 slave_name[t], slave_filename[t]);
1160 fi = open(slave_filename[t], O_RDONLY|O_BINARY);
1162 msg("<fatal> Failed to open %s\n", slave_filename[t]);
1165 ret = swf_ReadSWF(fi, &slave);
1167 msg("<fatal> Failed to read from %s\n", slave_filename[t]);
1170 msg("<debug> Read %d bytes from slavefile\n", ret);
1175 memset(&slave, 0, sizeof(slave));
1176 slave.firstTag = swf_InsertTag(0, ST_END);
1177 slave.frameRate = 0;
1178 slave.fileVersion = 4;
1179 slave.frameCount = 0;
1182 combine(&master, slave_name[t], &slave, &newswf);
1187 fi = open(outputname, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);
1190 swf_WriteSWC(fi, &newswf);
1192 newswf.compressed = 0;
1193 swf_WriteSWF(fi, &newswf);