2 main routine for swfcombine(1), a tool for merging .swf-files.
4 Part of the swftools package.
6 Copyright (c) 2001 Matthias Kramm <kramm@quiss.org>
8 This file is distributed under the GPL, see file COPYING for details */
14 #include "../lib/rfxswf.h"
15 #include "../lib/args.h"
16 #include "../lib/log.h"
17 #include "../config.h"
43 struct config_t config;
45 char * master_filename = 0;
46 char * master_name = 0;
47 char * slave_filename[128];
48 char * slave_name[128];
51 float slave_scalex[128];
52 float slave_scaley[128];
53 char slave_isframe[128];
56 char * outputname = "output.swf";
58 int args_callback_option(char*name,char*val) {
64 else if(!strcmp(name,"l"))
69 else if (!strcmp(name, "o"))
74 else if (!strcmp(name, "v"))
79 else if (!strcmp(name, "a"))
84 else if (!strcmp(name, "A"))
89 else if (!strcmp(name, "x"))
91 config.movex = atoi(val);
94 else if (!strcmp(name, "y"))
96 config.movey = atoi(val);
99 else if (!strcmp(name, "m"))
104 else if (!strcmp(name, "f"))
109 else if (!strcmp(name, "d"))
114 else if (!strcmp(name, "z"))
119 else if (!strcmp(name, "r"))
121 config.framerate = atoi(val)*256/100;
124 else if (!strcmp(name, "X"))
126 config.sizex = atoi(val)*20;
130 else if (!strcmp(name, "Y"))
132 config.sizey = atoi(val)*20;
136 else if (!strcmp(name, "s"))
138 config.scalex = config.scaley = atoi(val)/100.0;
141 else if (!strcmp(name, "t") || !strcmp(name, "T"))
143 if(master_filename) {
144 fprintf(stderr, "error with arguments. Try --help.\n");
148 if(!strcmp(name,"T"))
150 master_filename = "__none__";
153 else if (!strcmp(name, "V"))
155 printf("swfcombine - part of %s %s\n", PACKAGE, VERSION);
160 fprintf(stderr, "Unknown option: -%s\n", name);
165 struct options_t options[] =
187 int args_callback_longoption(char*name,char*val) {
188 return args_long2shortoption(options, name, val);
191 int args_callback_command(char*name, char*val) {
192 char*myname = strdup(name);
194 filename = strchr(myname, '=');
199 // argument has no explicit name field. guess one from the file name
200 char*path = strrchr(myname, '/');
201 char*ext = strrchr(myname, '.');
202 if(!path) path = myname;
209 if(!master_filename) {
210 master_filename = filename;
211 master_name = myname;
213 logf("<verbose> slave entity %s (named \"%s\")\n", filename, myname);
215 slave_filename[numslaves] = filename;
216 slave_name[numslaves] = myname;
217 slave_movex[numslaves] = config.movex;
218 slave_movey[numslaves] = config.movey;
219 slave_scalex[numslaves] = config.scalex;
220 slave_scaley[numslaves] = config.scaley;
221 slave_isframe[numslaves] = config.isframe;
223 config.movex = config.movey = 0;
224 config.scalex = config.scaley = 1.0;
230 void args_callback_usage(char*name)
232 printf("Usage: %s [-rXYomlcv] [-f] masterfile [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
233 printf("OR: %s [-rXYomv] --stack[1] [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
234 printf("OR: %s [-rXYov] --cat [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
235 printf("OR: %s [-rXYomlcv] --dummy [-xys] [file]\n", name);
237 printf("-o outputfile --output explicitly specify output file. (otherwise, output.swf will be used\n");
238 printf("-t --stack place each slave in a seperate frame (no master movie)\n");
239 printf("-T --stack1 place each slave in the first frame (no master movie)\n");
240 printf("-m --merge Don't store the slaves in Sprites/MovieClips\n");
241 printf("-a --cat concatenate all slave files (no master movie)\n");
242 printf("-l --overlay Don't remove any master objects, only overlay new objects\n");
243 printf("-c --clip Clip the slave objects by the corresponding master objects\n");
244 printf("-v --verbose Use more than one -v for greater effect \n");
245 printf("-d --dummy Don't require slave objects \n");
246 printf("-f --frame The following identifier is a frame or framelabel, not an id or objectname\n");
247 printf("-x xpos --movex x Adjust position of slave by xpos twips (1/20 pixel)\n");
248 printf("-y ypos --movey y Adjust position of slave by ypos twips (1/20 pixel)\n");
249 printf("-s scale --scale Adjust size of slave by scale%\n");
250 printf("-r framerate --rate Set movie framerate (100 frames/sec)\n");
251 printf("-X width --width Force movie width to scale (default: use master width (not with -t))\n");
252 printf("-Y height --height Force movie height to scale (default: use master height (not with -t))\n");
253 printf("-z zlib --zlib Enable Flash 6 (MX) Zlib Compression\n");
256 static void makestackmaster(SWF*swf)
265 memset(&box, 0, sizeof(box));
267 /* scan all slaves for bounding box */
268 for(t=numslaves-1;t>=0;t--)
272 int fi=open(slave_filename[t],O_RDONLY);
274 if(fi<0 || swf_ReadSWF(fi, &head)<0) {
275 logf("<fatal> Couldn't open/read %s.", slave_filename[t]);
279 logf("<verbose> File %s has bounding box %d:%d:%d:%d\n",
281 head.movieSize.xmin, head.movieSize.ymin,
282 head.movieSize.xmax, head.movieSize.ymax);
286 if(tag->id == ST_SETBACKGROUNDCOLOR && tag->len>=3) {
287 rgb.r = tag->data[0];
288 rgb.g = tag->data[1];
289 rgb.b = tag->data[2];
293 frameRate = head.frameRate;
294 if(head.fileVersion > fileversion)
295 fileversion = head.fileVersion;
297 box = head.movieSize;
299 if(head.movieSize.xmin < box.xmin)
300 box.xmin = head.movieSize.xmin;
301 if(head.movieSize.ymin < box.ymin)
302 box.ymin = head.movieSize.ymin;
303 if(head.movieSize.xmax > box.xmax)
304 box.xmax = head.movieSize.xmax;
305 if(head.movieSize.ymax > box.ymax)
306 box.ymax = head.movieSize.ymax;
308 logf("<verbose> New master bounding box is %d:%d:%d:%d\n",
314 memset(swf, 0, sizeof(SWF));
315 swf->fileVersion = fileversion;
316 swf->movieSize = box;
317 swf->frameRate = frameRate;
319 swf->firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
321 swf_SetRGB(tag, &rgb);
323 for(t=0;t<numslaves;t++)
326 sprintf(buf, "Frame%02d", t);
327 slave_name[t] = strdup(buf);
329 tag = swf_InsertTag(tag, ST_DEFINESPRITE);
330 swf_SetU16(tag, t+1);
332 tag = swf_InsertTag(tag, ST_END);
333 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
334 swf_ObjectPlace(tag, t+1, 1+t,0,0, slave_name[t]);
336 if(!config.stack1 || t == numslaves-1) {
337 tag = swf_InsertTag(tag, ST_SHOWFRAME);
342 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
343 swf_SetU16(tag, 1+t);
346 tag = swf_InsertTag(tag, ST_END);
347 logf("<verbose> temporary SWF created");
350 static char* slavename = 0;
351 static int slaveid = -1;
352 static int slaveframe = -1;
353 static char masterbitmap[65536];
355 #define FLAGS_WRITEDEFINES 1
356 #define FLAGS_WRITENONDEFINES 2
357 #define FLAGS_WRITESPRITE 4
358 #define FLAGS_WRITESLAVE 8
360 int get_free_id(char*bitmap)
371 void jpeg_assert(SWF*master, SWF*slave)
373 /* TODO: if there's a jpegtable found, store it
374 and handle it together with the flash file
377 /* check that master and slave don't have both
378 jpegtables (which would be fatal) */
380 TAG *mpos=0, *spos=0;
383 mtag = master->firstTag;
384 stag = slave->firstTag;
387 if(mtag->id == ST_JPEGTABLES)
393 if(stag->id == ST_JPEGTABLES)
399 if(spos->len == mpos->len &&
400 !memcmp(spos->data, mpos->data, mpos->len))
402 // ok, both have jpegtables, but they're identical.
403 // delete one and don't throw an error
409 logf("<error> Master and slave have incompatible JPEGTABLES.");
413 TAG* write_sprite_defines(TAG*tag, SWF*sprite)
415 TAG*rtag = sprite->firstTag;
416 while(rtag && rtag->id!=ST_END) {
417 if(!swf_isAllowedSpriteTag(rtag)) {
418 logf("<debug> processing sprite tag %02x", tag->id);
419 if(swf_isDefiningTag(rtag))
421 logf("<debug> [sprite defs] write tag %02x (%d bytes in body)",
423 tag = swf_InsertTag(tag, rtag->id);
424 swf_SetBlock(tag, rtag->data, rtag->len);
426 else if(swf_isPseudoDefiningTag(rtag))
428 logf("<debug> [sprite defs] write tag %02x (%d bytes in body)",
430 tag = swf_InsertTag(tag, rtag->id);
431 swf_SetBlock(tag, rtag->data, rtag->len);
437 /* if we get here, jpeg_assert has already run,
438 ensuring this is the only one of it's kind,
439 so we may safely write it out */
440 tag = swf_InsertTag(tag, rtag->id);
441 swf_SetBlock(tag, rtag->data, rtag->len);
443 case ST_EXPORTASSETS:
444 logf("<debug> deliberately ignoring EXPORTASSETS tag");
446 case ST_ENABLEDEBUGGER:
447 logf("<debug> deliberately ignoring ENABLEDEBUGGER tag");
449 case ST_SETBACKGROUNDCOLOR:
450 logf("<debug> deliberately ignoring BACKGROUNDCOLOR tag");
455 logf("<notice> found tag %d. This is a Generator template, isn't it?", tag->id);
458 logf("<notice> funny tag: %d is neither defining nor sprite", tag->id);
467 void changedepth(TAG*tag, int add)
469 /* fucking byteorders */
470 if(tag->id == ST_PLACEOBJECT)
471 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
472 if(tag->id == ST_PLACEOBJECT2)
473 PUT16(&tag->data[1],GET16(&tag->data[1])+add);
474 if(tag->id == ST_REMOVEOBJECT)
475 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
476 if(tag->id == ST_REMOVEOBJECT2)
477 PUT16(&tag->data[0],GET16(&tag->data[0])+add);
480 void matrix_adjust(MATRIX*m)
482 m->sx = (int)(m->sx*config.scalex);
483 m->sy = (int)(m->sy*config.scaley);
484 m->r0 = (int)(m->r0*config.scalex);
485 m->r1 = (int)(m->r1*config.scaley);
486 m->tx += config.movex;
487 m->ty += config.movey;
490 void write_changepos(TAG*output, TAG*tag)
492 if(config.movex || config.movey || config.scalex != 1 || config.scaley != 1)
496 case ST_PLACEOBJECT2: {
499 swf_GetMatrix(0, &m);
501 flags = swf_GetU8(tag);
502 swf_SetU8(output, flags|4);
503 swf_SetU16(output, swf_GetU16(tag)); //depth
506 swf_SetU16(output, swf_GetU16(tag)); //id
509 swf_GetMatrix(tag, &m);
511 swf_SetMatrix(output, &m);
513 //swf_ResetReadBits(tag);
514 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
517 case ST_PLACEOBJECT: {
519 swf_SetU16(output, swf_GetU16(tag)); //id
520 swf_SetU16(output, swf_GetU16(tag)); //depth
522 swf_GetMatrix(tag, &m);
524 swf_SetMatrix(output, &m);
526 //swf_ResetReadBits(tag);
527 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
531 swf_SetBlock(output, tag->data, tag->len);
536 swf_SetBlock(output, tag->data, tag->len);
540 TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
542 TAG* definespritetag;
546 definespritetag = tag = swf_InsertTag(tag, ST_DEFINESPRITE);
547 swf_SetU16(tag, spriteid);
548 swf_SetU16(tag, sprite->frameCount);
549 logf ("<notice> sprite id is %d", spriteid);
551 tmp = sprite->frameCount;
552 logf("<debug> %d frames to go",tmp);
555 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
556 swf_SetU8(tag, 2+64); //flags: character+clipdepth
557 swf_SetU16(tag, 0); //depth
558 swf_SetU16(tag, replaceddefine); //id
559 swf_SetU16(tag, 65535); //clipdepth
562 if(config.overlay && !config.isframe) {
563 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
564 swf_SetU8(tag, 2); //flags: character
565 swf_SetU16(tag, 0); //depth
566 swf_SetU16(tag, replaceddefine); //id
569 rtag = sprite->firstTag;
570 while(rtag && rtag->id!=ST_END)
572 if (swf_isAllowedSpriteTag(rtag)) {
574 logf("<debug> [sprite main] write tag %02x (%d bytes in body)",
575 rtag->id, rtag->len);
576 tag = swf_InsertTag(tag, rtag->id);
577 write_changepos(tag, rtag);
579 changedepth(tag, +1);
581 if(tag->id == ST_SHOWFRAME)
584 logf("<debug> %d frames to go",tmp);
589 tag = swf_InsertTag(tag, ST_END);
593 static char tag_ok_for_slave(int id)
595 if(id == ST_SETBACKGROUNDCOLOR)
600 TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefine, int flags)
605 int slavewritten = 0;
607 TAG* rtag = master->firstTag;
608 TAG* stag = slave->firstTag;
610 while(rtag && rtag->id!=ST_END)
612 if(rtag->id == ST_SHOWFRAME && outputslave)
614 while(stag && stag->id!=ST_END) {
615 if(stag->id == ST_SHOWFRAME) {
620 if(tag_ok_for_slave(stag->id)) {
621 tag = swf_InsertTag(tag, stag->id);
622 swf_SetBlock(tag, stag->data, stag->len);
627 if(rtag->id == ST_SHOWFRAME)
632 if(swf_isDefiningTag(rtag) && (flags&FLAGS_WRITEDEFINES))
634 logf("<debug> [master] write tag %02x (%d bytes in body)",
635 rtag->id, rtag->len);
636 if(swf_GetDefineID(rtag) == spriteid && !config.isframe)
640 tag = swf_InsertTag(tag, rtag->id);
641 swf_SetBlock(tag, rtag->data, rtag->len);
642 swf_SetDefineID(tag, replaceddefine);
644 /* don't write this tag */
645 logf("<verbose> replacing tag %d id %d with sprite", rtag->id
649 if(flags&FLAGS_WRITESPRITE)
651 tag = write_sprite_defines(tag, slave);
652 tag = write_sprite(tag, slave, spriteid, replaceddefine);
654 if(flags&FLAGS_WRITESLAVE)
659 tag = swf_InsertTag(tag, rtag->id);
660 swf_SetBlock(tag, rtag->data, rtag->len);
663 if(frame == slaveframe)
665 if(flags&FLAGS_WRITESLAVE) {
669 if((flags&FLAGS_WRITESPRITE) && !slavewritten)
671 int id = get_free_id(masterbitmap);
674 logf("<fatal> Can't combine --clip and --frame");
677 tag = write_sprite_defines(tag, slave);
678 tag = write_sprite(tag, slave, id, -1);
680 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
681 swf_SetU8(tag, 2); //flags: id
682 swf_SetU16(tag, depth);
688 if(!swf_isDefiningTag(rtag) && (flags&FLAGS_WRITENONDEFINES))
693 case ST_PLACEOBJECT2:
694 if(frame == slaveframe && !config.overlay)
696 case ST_REMOVEOBJECT:
697 // case ST_REMOVEOBJECT2:
698 /* place/removetags for the object we replaced
699 should be discarded, too, as the object to insert
702 if(spriteid>=0 && swf_GetPlaceID(rtag) == spriteid &&
703 !config.isframe && config.merge)
708 logf("<debug> [master] write tag %02x (%d bytes in body)",
709 rtag->id, rtag->len);
710 tag = swf_InsertTag(tag, rtag->id);
711 swf_SetBlock(tag, rtag->data, rtag->len);
718 while(stag && stag->id!=ST_END)
720 if(tag_ok_for_slave(stag->id)) {
721 tag = swf_InsertTag(tag, stag->id);
722 swf_SetBlock(tag, stag->data, stag->len);
726 if(!slavewritten && config.isframe && (flags&(FLAGS_WRITESLAVE|FLAGS_WRITESPRITE)))
729 logf("<warning> Frame %d doesn't exist in file. No substitution will occur",
732 logf("<warning> Frame \"%s\" doesn't exist in file. No substitution will occur",
735 tag = swf_InsertTag(tag, ST_END);
739 void adjustheader(SWF*swf)
742 swf->frameRate = config.framerate;
743 if(config.hassizex) {
744 swf->movieSize.xmax =
745 swf->movieSize.xmin + config.sizex;
747 if(config.hassizey) {
748 swf->movieSize.ymax =
749 swf->movieSize.ymin + config.sizey;
753 void catcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
760 logf("<fatal> Can't combine --cat and --frame");
764 tag = master->firstTag;
767 if(swf_isDefiningTag(tag)) {
768 int defineid = swf_GetDefineID(tag);
769 logf("<debug> tagid %02x defines object %d", tag->id, defineid);
770 masterbitmap[defineid] = 1;
775 swf_Relocate(slave, masterbitmap);
776 jpeg_assert(master, slave);
778 memcpy(newswf, master, sizeof(SWF));
779 adjustheader(newswf);
781 tag = newswf->firstTag = swf_InsertTag(0, ST_REFLEX); // to be removed later
783 depths = malloc(65536);
785 logf("<fatal> Couldn't allocate %d bytes of memory", 65536);
788 memset(depths, 0, 65536);
789 mtag = master->firstTag;
790 while(mtag && mtag->id!=ST_END)
794 logf("<debug> [master] write tag %02x (%d bytes in body)",
795 mtag->id, mtag->len);
797 case ST_PLACEOBJECT2:
799 case ST_PLACEOBJECT: {
800 depth = swf_GetDepth(mtag);
804 case ST_REMOVEOBJECT: {
805 depth = swf_GetDepth(mtag);
809 case ST_REMOVEOBJECT2: {
810 depth = swf_GetDepth(mtag);
815 tag = swf_InsertTag(tag, mtag->id);
816 swf_SetBlock(tag, mtag->data, mtag->len);
826 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
831 stag = slave->firstTag;
832 while(stag && stag->id!=ST_END)
834 logf("<debug> [slave] write tag %02x (%d bytes in body)",
835 stag->id, stag->len);
836 tag = swf_InsertTag(tag, stag->id);
837 swf_SetBlock(tag, stag->data, stag->len);
840 tag = swf_InsertTag(tag, ST_END);
842 tag = newswf->firstTag;
843 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
847 void normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
850 int replaceddefine = -1;
853 TAG * tag = master->firstTag;
858 if(swf_isDefiningTag(tag)) {
859 int defineid = swf_GetDefineID(tag);
860 logf("<debug> tagid %02x defines object %d", tag->id, defineid);
861 masterbitmap[defineid] = 1;
862 } else if(tag->id == ST_PLACEOBJECT2) {
863 char * name = swf_GetName(tag);
864 int id = swf_GetPlaceID(tag);
867 logf("<verbose> tagid %02x places object %d named \"%s\"", tag->id, id, name);
869 logf("<verbose> tagid %02x places object %d (no name)", tag->id, id);
871 if ((name && slavename && !strcmp(name,slavename)) ||
872 (!slavename && id==slaveid)) {
875 logf("<notice> Slave file attached to object %d.", id);
878 } else if(tag->id == ST_SHOWFRAME) {
879 if(slaveframe>=0 && frame==slaveframe) {
880 logf("<notice> Slave file attached to frame %d.", frame);
883 } else if(tag->id == ST_FRAMELABEL) {
884 char * name = tag->data;
885 if(name && slavename && config.isframe && !strcmp(name, slavename)) {
887 logf("<notice> Slave file attached to frame %d (%s).", frame, name);
893 if (spriteid<0 && !config.isframe) {
895 if(strcmp(slavename,"!!dummy!!"))
896 logf("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
899 logf("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
900 spriteid = get_free_id(masterbitmap);
903 swf_Relocate (slave, masterbitmap);
904 jpeg_assert(slave, master);
907 replaceddefine = get_free_id(masterbitmap);
911 memcpy(newswf, master, sizeof(SWF));
912 adjustheader(newswf);
914 newswf->firstTag = tag = swf_InsertTag(0, ST_REFLEX); // to be removed later
916 if (config.antistream) {
918 logf("<fatal> Can't combine --antistream and --merge");
920 tag = write_sprite_defines(tag, slave);
921 tag = write_sprite(tag, slave, spriteid, replaceddefine);
922 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITEDEFINES);
923 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITENONDEFINES);
926 tag = write_master(tag, master, slave, spriteid, replaceddefine,
927 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES|FLAGS_WRITESLAVE);
929 tag = write_master(tag, master, slave, spriteid, replaceddefine,
930 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES|FLAGS_WRITESPRITE);
933 tag = newswf->firstTag;
934 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
938 void combine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
940 slavename = slave_name;
947 if(slavename[0] == '#')
949 slaveid = atoi(&slavename[1]);
956 if(slavename && slavename[0]!='#' && (sscanf(slavename, "%d", &tmp) ==
957 strlen(slavename))) {
958 /* if the name the slave should replace
959 consists only of digits and the -f
960 option is given, it probably is not
961 a frame name but a frame number.
968 slaveframe = slaveid;
971 /* if id wasn't given as either #number or number,
972 the name is a frame label. BTW: The user wouldn't have
973 needed to supply the -f option in this case */
977 logf("<debug> move x (%d)", config.movex);
978 logf("<debug> move y (%d)", config.movey);
979 logf("<debug> scale x (%f)", config.scalex);
980 logf("<debug> scale y (%f)", config.scaley);
981 logf("<debug> is frame (%d)", config.isframe);
983 memset(masterbitmap, 0, sizeof(masterbitmap));
986 return catcombine(master, slave_name, slave, newswf);
988 return normalcombine(master, slave_name, slave, newswf);
991 int main(int argn, char *argv[])
1000 config.antistream = 0;
1001 config.alloctest = 0;
1005 config.loglevel = 2;
1008 config.scalex = 1.0;
1009 config.scaley = 1.0;
1012 config.hassizex = 0;
1013 config.hassizey = 0;
1014 config.framerate = 0;
1020 processargs(argn, argv);
1021 initLog(0,-1,0,0,-1,config.loglevel);
1023 if(config.merge && config.cat) {
1024 logf("<error> Can't combine --cat and --merge");
1029 if(config.overlay) {
1030 logf("<error> Can't combine -l and -t");
1034 logf("<error> Can't combine -c and -t");
1037 logf("<verbose> (stacking) %d files found\n", numslaves);
1039 makestackmaster(&master);
1043 logf("<verbose> master entity %s (named \"%s\")\n", master_filename, master_name);
1044 fi = open(master_filename, O_RDONLY);
1046 logf("<fatal> Failed to open %s\n", master_filename);
1049 ret = swf_ReadSWF(fi, &master);
1051 logf("<fatal> Failed to read from %s\n", master_filename);
1054 logf("<debug> Read %d bytes from masterfile\n", ret);
1058 for(t=0;t<numslaves;t++) {
1059 logf("<verbose> slave entity(%d) %s (%s \"%s\")\n", t+1, slave_filename[t],
1060 slave_isframe[t]?"frame":"object", slave_name[t]);
1067 logf("<error> --dummy (-d) implies there are zero slave objects. You supplied %d.", numslaves);
1071 slave_filename[0] = "!!dummy!!";
1072 slave_name[0] = "!!dummy!!";
1073 slave_isframe[0] = 0;
1076 if (config.alloctest)
1078 char*bitmap = malloc(sizeof(char)*65536);
1079 memset(bitmap, 0, 65536*sizeof(char));
1080 memset(bitmap, 1, 101*sizeof(char));
1081 swf_Relocate(&master, bitmap);
1084 // makestackmaster(&newswf);
1091 logf("<error> You must have at least two objects.");
1093 logf("<error> You must have at least one slave entity.");
1096 for(t = 0; t < numslaves; t++)
1098 config.movex = slave_movex[t];
1099 config.movey = slave_movey[t];
1100 config.scalex = slave_scalex[t];
1101 config.scaley = slave_scaley[t];
1102 config.isframe = slave_isframe[t];
1104 logf("<notice> Combine [%s]%s and [%s]%s", master_name, master_filename,
1105 slave_name[t], slave_filename[t]);
1109 fi = open(slave_filename[t], O_RDONLY);
1111 logf("<fatal> Failed to open %s\n", slave_filename[t]);
1114 ret = swf_ReadSWF(fi, &slave);
1116 logf("<fatal> Failed to read from %s\n", slave_filename[t]);
1119 logf("<debug> Read %d bytes from slavefile\n", ret);
1124 memset(&slave, 0, sizeof(slave));
1125 slave.firstTag = swf_InsertTag(0, ST_END);
1126 slave.frameRate = 0;
1127 slave.fileVersion = 4;
1128 slave.frameCount = 0;
1131 combine(&master, slave_name[t], &slave, &newswf);
1136 fi = open(outputname, O_RDWR|O_TRUNC|O_CREAT, 0777);
1139 swf_WriteSWC(fi, &newswf);
1141 newswf.compressed = 0;
1142 swf_WriteSWF(fi, &newswf);