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"
47 struct config_t config;
49 char * master_filename = 0;
50 char * master_name = 0;
51 char * slave_filename[128];
52 char * slave_name[128];
55 float slave_scalex[128];
56 float slave_scaley[128];
57 char slave_isframe[128];
60 char * outputname = "output.swf";
62 int args_callback_option(char*name,char*val) {
68 else if(!strcmp(name,"l"))
73 else if (!strcmp(name, "o"))
78 else if (!strcmp(name, "v"))
83 else if (!strcmp(name, "a"))
88 else if (!strcmp(name, "A"))
93 else if (!strcmp(name, "x"))
95 config.movex = atoi(val);
98 else if (!strcmp(name, "y"))
100 config.movey = atoi(val);
103 else if (!strcmp(name, "m"))
108 else if (!strcmp(name, "f"))
113 else if (!strcmp(name, "d"))
118 else if (!strcmp(name, "z"))
123 else if (!strcmp(name, "r"))
125 config.framerate = atoi(val)*256/100;
128 else if (!strcmp(name, "X"))
130 config.sizex = atoi(val)*20;
134 else if (!strcmp(name, "Y"))
136 config.sizey = atoi(val)*20;
140 else if (!strcmp(name, "s"))
142 config.scalex = config.scaley = atoi(val)/100.0;
145 else if (!strcmp(name, "t") || !strcmp(name, "T"))
147 if(master_filename) {
148 fprintf(stderr, "error with arguments. Try --help.\n");
152 if(!strcmp(name,"T"))
154 master_filename = "__none__";
157 else if (!strcmp(name, "V"))
159 printf("swfcombine - part of %s %s\n", PACKAGE, VERSION);
164 fprintf(stderr, "Unknown option: -%s\n", name);
169 struct options_t options[] =
191 int args_callback_longoption(char*name,char*val) {
192 return args_long2shortoption(options, name, val);
195 int args_callback_command(char*name, char*val) {
196 char*myname = strdup(name);
198 filename = strchr(myname, '=');
203 // argument has no explicit name field. guess one from the file name
204 char*path = strrchr(myname, '/');
205 char*ext = strrchr(myname, '.');
206 if(!path) path = myname;
213 if(!master_filename) {
214 master_filename = filename;
215 master_name = myname;
216 config.mastermovex = config.movex;
217 config.mastermovey = config.movey;
218 config.masterscalex = config.scalex;
219 config.masterscaley = config.scaley;
220 config.movex = config.movey = 0;
221 config.scalex = config.scaley = 1.0;
223 logf("<verbose> slave entity %s (named \"%s\")\n", filename, myname);
225 slave_filename[numslaves] = filename;
226 slave_name[numslaves] = myname;
227 slave_movex[numslaves] = config.movex;
228 slave_movey[numslaves] = config.movey;
229 slave_scalex[numslaves] = config.scalex;
230 slave_scaley[numslaves] = config.scaley;
231 slave_isframe[numslaves] = config.isframe;
233 config.movex = config.movey = 0;
234 config.scalex = config.scaley = 1.0;
240 void args_callback_usage(char*name)
242 printf("Usage: %s [-rXYomlcv] [-f] masterfile [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
243 printf("OR: %s [-rXYomv] --stack[1] [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
244 printf("OR: %s [-rXYov] --cat [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
245 printf("OR: %s [-rXYomlcv] --dummy [-xys] [file]\n", name);
247 printf("-o outputfile --output explicitly specify output file. (otherwise, output.swf will be used)\n");
248 printf("-t --stack place each slave in a seperate frame (no master movie)\n");
249 printf("-T --stack1 place each slave in the first frame (no master movie)\n");
250 printf("-m --merge Don't store the slaves in Sprites/MovieClips\n");
251 printf("-a --cat concatenate all slave files (no master movie)\n");
252 printf("-l --overlay Don't remove any master objects, only overlay new objects\n");
253 printf("-c --clip Clip the slave objects by the corresponding master objects\n");
254 printf("-v --verbose Use more than one -v for greater effect \n");
255 printf("-d --dummy Don't require slave objects \n");
256 printf("-f --frame The following identifier is a frame or framelabel, not an id or objectname\n");
257 printf("-x xpos --movex x Adjust position of slave by xpos twips (1/20 pixel)\n");
258 printf("-y ypos --movey y Adjust position of slave by ypos twips (1/20 pixel)\n");
259 printf("-s scale --scale Adjust size of slave by scale%\n");
260 printf("-r framerate --rate Set movie framerate (100 frames/sec)\n");
261 printf("-X width --width Force movie width to scale (default: use master width (not with -t))\n");
262 printf("-Y height --height Force movie height to scale (default: use master height (not with -t))\n");
263 printf("-z zlib --zlib Enable Flash 6 (MX) Zlib Compression\n");
266 static void makestackmaster(SWF*swf)
275 memset(&box, 0, sizeof(box));
277 /* scan all slaves for bounding box */
278 for(t=numslaves-1;t>=0;t--)
282 int fi=open(slave_filename[t],O_RDONLY);
284 if(fi<0 || swf_ReadSWF(fi, &head)<0) {
285 logf("<fatal> Couldn't open/read %s.", slave_filename[t]);
289 logf("<verbose> File %s has bounding box %d:%d:%d:%d\n",
291 head.movieSize.xmin, head.movieSize.ymin,
292 head.movieSize.xmax, head.movieSize.ymax);
296 if(tag->id == ST_SETBACKGROUNDCOLOR && tag->len>=3) {
297 rgb.r = tag->data[0];
298 rgb.g = tag->data[1];
299 rgb.b = tag->data[2];
303 frameRate = head.frameRate;
304 if(head.fileVersion > fileversion)
305 fileversion = head.fileVersion;
307 box = head.movieSize;
309 if(head.movieSize.xmin < box.xmin)
310 box.xmin = head.movieSize.xmin;
311 if(head.movieSize.ymin < box.ymin)
312 box.ymin = head.movieSize.ymin;
313 if(head.movieSize.xmax > box.xmax)
314 box.xmax = head.movieSize.xmax;
315 if(head.movieSize.ymax > box.ymax)
316 box.ymax = head.movieSize.ymax;
318 logf("<verbose> New master bounding box is %d:%d:%d:%d\n",
324 memset(swf, 0, sizeof(SWF));
325 swf->fileVersion = fileversion;
326 swf->movieSize = box;
327 swf->frameRate = frameRate;
329 swf->firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
331 swf_SetRGB(tag, &rgb);
333 for(t=0;t<numslaves;t++)
336 sprintf(buf, "Frame%02d", t);
337 slave_name[t] = strdup(buf);
339 tag = swf_InsertTag(tag, ST_DEFINESPRITE);
340 swf_SetU16(tag, t+1);
342 tag = swf_InsertTag(tag, ST_END);
343 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
344 swf_ObjectPlace(tag, t+1, 1+t,0,0, slave_name[t]);
346 if(!config.stack1 || t == numslaves-1) {
347 tag = swf_InsertTag(tag, ST_SHOWFRAME);
352 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
353 swf_SetU16(tag, 1+t);
356 tag = swf_InsertTag(tag, ST_END);
357 logf("<verbose> temporary SWF created");
360 static char* slavename = 0;
361 static int slaveid = -1;
362 static int slaveframe = -1;
363 static char masterbitmap[65536];
365 #define FLAGS_WRITEDEFINES 1
366 #define FLAGS_WRITENONDEFINES 2
367 #define FLAGS_WRITESPRITE 4
368 #define FLAGS_WRITESLAVE 8
370 int get_free_id(char*bitmap)
381 void jpeg_assert(SWF*master, SWF*slave)
383 /* TODO: if there's a jpegtable found, store it
384 and handle it together with the flash file
387 /* check that master and slave don't have both
388 jpegtables (which would be fatal) */
390 TAG *mpos=0, *spos=0;
393 mtag = master->firstTag;
394 stag = slave->firstTag;
397 if(mtag->id == ST_JPEGTABLES)
403 if(stag->id == ST_JPEGTABLES)
409 if(spos->len == mpos->len &&
410 !memcmp(spos->data, mpos->data, mpos->len))
412 // ok, both have jpegtables, but they're identical.
413 // delete one and don't throw an error
419 logf("<error> Master and slave have incompatible JPEGTABLES.");
423 TAG* write_sprite_defines(TAG*tag, SWF*sprite)
425 TAG*rtag = sprite->firstTag;
426 while(rtag && rtag->id!=ST_END) {
427 if(!swf_isAllowedSpriteTag(rtag)) {
428 logf("<debug> processing sprite tag %02x", tag->id);
429 if(swf_isDefiningTag(rtag))
431 logf("<debug> [sprite defs] write tag %02x (%d bytes in body)",
433 tag = swf_InsertTag(tag, rtag->id);
434 swf_SetBlock(tag, rtag->data, rtag->len);
436 else if(swf_isPseudoDefiningTag(rtag))
438 logf("<debug> [sprite defs] write tag %02x (%d bytes in body)",
440 tag = swf_InsertTag(tag, rtag->id);
441 swf_SetBlock(tag, rtag->data, rtag->len);
447 /* if we get here, jpeg_assert has already run,
448 ensuring this is the only one of it's kind,
449 so we may safely write it out */
450 tag = swf_InsertTag(tag, rtag->id);
451 swf_SetBlock(tag, rtag->data, rtag->len);
453 case ST_EXPORTASSETS:
454 logf("<debug> deliberately ignoring EXPORTASSETS tag");
456 case ST_ENABLEDEBUGGER:
457 logf("<debug> deliberately ignoring ENABLEDEBUGGER tag");
459 case ST_SETBACKGROUNDCOLOR:
460 logf("<debug> deliberately ignoring BACKGROUNDCOLOR tag");
465 logf("<notice> found tag %d. This is a Generator template, isn't it?", tag->id);
468 logf("<notice> funny tag: %d is neither defining nor sprite", tag->id);
477 void changedepth(TAG*tag, int add)
479 /* fucking byteorders */
480 if(tag->id == ST_PLACEOBJECT)
481 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
482 if(tag->id == ST_PLACEOBJECT2)
483 PUT16(&tag->data[1],GET16(&tag->data[1])+add);
484 if(tag->id == ST_REMOVEOBJECT)
485 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
486 if(tag->id == ST_REMOVEOBJECT2)
487 PUT16(&tag->data[0],GET16(&tag->data[0])+add);
490 void matrix_adjust(MATRIX*m, int movex, int movey, float scalex, float scaley)
492 m->sx = (int)(m->sx*scalex);
493 m->sy = (int)(m->sy*scaley);
494 m->r0 = (int)(m->r0*scalex);
495 m->r1 = (int)(m->r1*scaley);
500 void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, float scaley)
502 if(movex || movey || scalex != 1 || scaley != 1)
506 case ST_PLACEOBJECT2: {
509 swf_GetMatrix(0, &m);
513 flags = swf_GetU8(tag);
514 swf_SetU8(output, flags|4);
515 swf_SetU16(output, swf_GetU16(tag)); //depth
518 swf_SetU16(output, swf_GetU16(tag)); //id
522 swf_GetMatrix(tag, &m);
524 swf_GetMatrix(0, &m);
526 matrix_adjust(&m, movex, movey, scalex, scaley);
527 swf_SetMatrix(output, &m);
529 //swf_ResetReadBits(tag);
530 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
533 case ST_PLACEOBJECT: {
535 swf_SetU16(output, swf_GetU16(tag)); //id
536 swf_SetU16(output, swf_GetU16(tag)); //depth
538 swf_GetMatrix(tag, &m);
539 matrix_adjust(&m, movex, movey, scalex, scaley);
540 swf_SetMatrix(output, &m);
542 //swf_ResetReadBits(tag);
543 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
547 swf_SetBlock(output, tag->data, tag->len);
552 swf_SetBlock(output, tag->data, tag->len);
556 TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
558 TAG* definespritetag;
562 definespritetag = tag = swf_InsertTag(tag, ST_DEFINESPRITE);
563 swf_SetU16(tag, spriteid);
564 swf_SetU16(tag, sprite->frameCount);
565 logf ("<notice> sprite id is %d", spriteid);
567 tmp = sprite->frameCount;
568 logf("<debug> %d frames to go",tmp);
571 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
572 swf_SetU8(tag, 2+64); //flags: character+clipdepth
573 swf_SetU16(tag, 0); //depth
574 swf_SetU16(tag, replaceddefine); //id
575 swf_SetU16(tag, 65535); //clipdepth
578 if(config.overlay && !config.isframe) {
579 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
580 swf_SetU8(tag, 2); //flags: character
581 swf_SetU16(tag, 1); //depth
582 swf_SetU16(tag, replaceddefine); //id
585 rtag = sprite->firstTag;
586 while(rtag && rtag->id!=ST_END)
588 if (swf_isAllowedSpriteTag(rtag)) {
590 logf("<debug> [sprite main] write tag %02x (%d bytes in body)",
591 rtag->id, rtag->len);
592 tag = swf_InsertTag(tag, rtag->id);
593 write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley);
595 changedepth(tag, +2);
597 if(tag->id == ST_SHOWFRAME)
600 logf("<debug> %d frames to go",tmp);
605 tag = swf_InsertTag(tag, ST_END);
609 static char tag_ok_for_slave(int id)
611 if(id == ST_SETBACKGROUNDCOLOR)
616 TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefine, int flags)
621 int slavewritten = 0;
623 TAG* rtag = master->firstTag;
624 TAG* stag = slave->firstTag;
626 while(rtag && rtag->id!=ST_END)
628 if(rtag->id == ST_SHOWFRAME && outputslave)
630 while(stag && stag->id!=ST_END) {
631 if(stag->id == ST_SHOWFRAME) {
636 if(tag_ok_for_slave(stag->id)) {
637 tag = swf_InsertTag(tag, stag->id);
638 swf_SetBlock(tag, stag->data, stag->len);
643 if(rtag->id == ST_SHOWFRAME)
648 if(swf_isDefiningTag(rtag) && (flags&FLAGS_WRITEDEFINES))
650 logf("<debug> [master] write tag %02x (%d bytes in body)",
651 rtag->id, rtag->len);
652 if(swf_GetDefineID(rtag) == spriteid && !config.isframe)
656 tag = swf_InsertTag(tag, rtag->id);
657 swf_SetBlock(tag, rtag->data, rtag->len);
658 swf_SetDefineID(tag, replaceddefine);
660 /* don't write this tag */
661 logf("<verbose> replacing tag %d id %d with sprite", rtag->id
665 if(flags&FLAGS_WRITESPRITE)
667 tag = write_sprite_defines(tag, slave);
668 tag = write_sprite(tag, slave, spriteid, replaceddefine);
670 if(flags&FLAGS_WRITESLAVE)
675 tag = swf_InsertTag(tag, rtag->id);
676 swf_SetBlock(tag, rtag->data, rtag->len);
679 if(frame == slaveframe)
681 if(flags&FLAGS_WRITESLAVE) {
685 if((flags&FLAGS_WRITESPRITE) && !slavewritten)
687 int id = get_free_id(masterbitmap);
690 logf("<fatal> Can't combine --clip and --frame");
693 tag = write_sprite_defines(tag, slave);
694 tag = write_sprite(tag, slave, id, -1);
696 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
697 swf_SetU8(tag, 2); //flags: id
698 swf_SetU16(tag, depth);
704 if(!swf_isDefiningTag(rtag) && (flags&FLAGS_WRITENONDEFINES))
709 case ST_PLACEOBJECT2:
710 if(frame == slaveframe && !config.overlay)
712 case ST_REMOVEOBJECT:
713 /* place/removetags for the object we replaced
714 should be discarded, too, as the object to insert
717 if(spriteid>=0 && swf_GetPlaceID(rtag) == spriteid &&
718 !config.isframe && config.merge)
721 case ST_REMOVEOBJECT2:
725 logf("<debug> [master] write tag %02x (%d bytes in body)",
726 rtag->id, rtag->len);
727 tag = swf_InsertTag(tag, rtag->id);
728 write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley);
735 while(stag && stag->id!=ST_END)
737 if(tag_ok_for_slave(stag->id)) {
738 tag = swf_InsertTag(tag, stag->id);
739 swf_SetBlock(tag, stag->data, stag->len);
743 if(!slavewritten && config.isframe && (flags&(FLAGS_WRITESLAVE|FLAGS_WRITESPRITE)))
746 logf("<warning> Frame %d doesn't exist in file. No substitution will occur",
749 logf("<warning> Frame \"%s\" doesn't exist in file. No substitution will occur",
752 tag = swf_InsertTag(tag, ST_END);
756 void adjustheader(SWF*swf)
759 swf->frameRate = config.framerate;
760 if(config.hassizex) {
761 swf->movieSize.xmax =
762 swf->movieSize.xmin + config.sizex;
764 if(config.hassizey) {
765 swf->movieSize.ymax =
766 swf->movieSize.ymin + config.sizey;
770 void catcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
777 logf("<fatal> Can't combine --cat and --frame");
781 tag = master->firstTag;
784 if(swf_isDefiningTag(tag)) {
785 int defineid = swf_GetDefineID(tag);
786 logf("<debug> tagid %02x defines object %d", tag->id, defineid);
787 masterbitmap[defineid] = 1;
792 swf_Relocate(slave, masterbitmap);
793 jpeg_assert(master, slave);
795 memcpy(newswf, master, sizeof(SWF));
796 adjustheader(newswf);
798 tag = newswf->firstTag = swf_InsertTag(0, ST_REFLEX); // to be removed later
800 depths = malloc(65536);
802 logf("<fatal> Couldn't allocate %d bytes of memory", 65536);
805 memset(depths, 0, 65536);
806 mtag = master->firstTag;
807 while(mtag && mtag->id!=ST_END)
811 logf("<debug> [master] write tag %02x (%d bytes in body)",
812 mtag->id, mtag->len);
814 case ST_PLACEOBJECT2:
816 case ST_PLACEOBJECT: {
817 depth = swf_GetDepth(mtag);
821 case ST_REMOVEOBJECT: {
822 depth = swf_GetDepth(mtag);
826 case ST_REMOVEOBJECT2: {
827 depth = swf_GetDepth(mtag);
832 tag = swf_InsertTag(tag, mtag->id);
833 swf_SetBlock(tag, mtag->data, mtag->len);
843 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
848 stag = slave->firstTag;
849 while(stag && stag->id!=ST_END)
851 logf("<debug> [slave] write tag %02x (%d bytes in body)",
852 stag->id, stag->len);
853 tag = swf_InsertTag(tag, stag->id);
854 swf_SetBlock(tag, stag->data, stag->len);
857 tag = swf_InsertTag(tag, ST_END);
859 tag = newswf->firstTag;
860 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
864 void normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
867 int replaceddefine = -1;
870 TAG * tag = master->firstTag;
875 if(swf_isDefiningTag(tag)) {
876 int defineid = swf_GetDefineID(tag);
877 logf("<debug> tagid %02x defines object %d", tag->id, defineid);
878 masterbitmap[defineid] = 1;
879 if (!slavename && defineid==slaveid) {
882 logf("<notice> Slave file attached to object %d.", defineid);
885 } else if(tag->id == ST_PLACEOBJECT2) {
886 char * name = swf_GetName(tag);
887 int id = swf_GetPlaceID(tag);
890 logf("<verbose> tagid %02x places object %d named \"%s\"", tag->id, id, name);
892 logf("<verbose> tagid %02x places object %d (no name)", tag->id, id);
894 if (name && slavename && !strcmp(name,slavename)) {
897 logf("<notice> Slave file attached to named object %s (%d).", name, id);
900 } else if(tag->id == ST_SHOWFRAME) {
901 if(slaveframe>=0 && frame==slaveframe) {
902 logf("<notice> Slave file attached to frame %d.", frame);
905 } else if(tag->id == ST_FRAMELABEL) {
906 char * name = tag->data;
907 if(name && slavename && config.isframe && !strcmp(name, slavename)) {
909 logf("<notice> Slave file attached to frame %d (%s).", frame, name);
915 if (spriteid<0 && !config.isframe) {
917 if(strcmp(slavename,"!!dummy!!"))
918 logf("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
921 logf("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
922 spriteid = get_free_id(masterbitmap);
925 swf_Relocate (slave, masterbitmap);
926 jpeg_assert(slave, master);
929 replaceddefine = get_free_id(masterbitmap);
933 memcpy(newswf, master, sizeof(SWF));
934 adjustheader(newswf);
936 newswf->firstTag = tag = swf_InsertTag(0, ST_REFLEX); // to be removed later
938 if (config.antistream) {
940 logf("<fatal> Can't combine --antistream and --merge");
942 tag = write_sprite_defines(tag, slave);
943 tag = write_sprite(tag, slave, spriteid, replaceddefine);
944 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITEDEFINES);
945 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITENONDEFINES);
948 tag = write_master(tag, master, slave, spriteid, replaceddefine,
949 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESLAVE );
951 tag = write_master(tag, master, slave, spriteid, replaceddefine,
952 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESPRITE );
955 tag = newswf->firstTag;
956 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
960 void combine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
962 slavename = slave_name;
969 if(slavename[0] == '#')
971 slaveid = atoi(&slavename[1]);
978 if(slavename && slavename[0]!='#' && (sscanf(slavename, "%d", &tmp) ==
979 strlen(slavename))) {
980 /* if the name the slave should replace
981 consists only of digits and the -f
982 option is given, it probably is not
983 a frame name but a frame number.
990 slaveframe = slaveid;
993 /* if id wasn't given as either #number or number,
994 the name is a frame label. BTW: The user wouldn't necessarily have
995 needed to supply the -f option in this case */
999 logf("<debug> move x (%d)", config.movex);
1000 logf("<debug> move y (%d)", config.movey);
1001 logf("<debug> scale x (%f)", config.scalex);
1002 logf("<debug> scale y (%f)", config.scaley);
1003 logf("<debug> master move x (%d)", config.mastermovex);
1004 logf("<debug> master move y (%d)", config.mastermovey);
1005 logf("<debug> master scale x (%f)", config.masterscalex);
1006 logf("<debug> master scale y (%f)", config.masterscaley);
1007 logf("<debug> is frame (%d)", config.isframe);
1009 memset(masterbitmap, 0, sizeof(masterbitmap));
1012 return catcombine(master, slave_name, slave, newswf);
1014 return normalcombine(master, slave_name, slave, newswf);
1017 int main(int argn, char *argv[])
1026 config.antistream = 0;
1027 config.alloctest = 0;
1031 config.loglevel = 2;
1034 config.scalex = 1.0;
1035 config.scaley = 1.0;
1038 config.masterscalex = 1.0;
1039 config.masterscaley = 1.0;
1040 config.mastermovex = 0;
1041 config.mastermovey = 0;
1042 config.hassizex = 0;
1043 config.hassizey = 0;
1044 config.framerate = 0;
1050 processargs(argn, argv);
1051 initLog(0,-1,0,0,-1,config.loglevel);
1053 if(config.merge && config.cat) {
1054 logf("<error> Can't combine --cat and --merge");
1059 if(config.overlay) {
1060 logf("<error> Can't combine -l and -t");
1064 logf("<error> Can't combine -c and -t");
1067 logf("<verbose> (stacking) %d files found\n", numslaves);
1069 makestackmaster(&master);
1073 logf("<verbose> master entity %s (named \"%s\")\n", master_filename, master_name);
1074 fi = open(master_filename, O_RDONLY);
1076 logf("<fatal> Failed to open %s\n", master_filename);
1079 ret = swf_ReadSWF(fi, &master);
1081 logf("<fatal> Failed to read from %s\n", master_filename);
1084 logf("<debug> Read %d bytes from masterfile\n", ret);
1088 for(t=0;t<numslaves;t++) {
1089 logf("<verbose> slave entity(%d) %s (%s \"%s\")\n", t+1, slave_filename[t],
1090 slave_isframe[t]?"frame":"object", slave_name[t]);
1097 logf("<error> --dummy (-d) implies there are zero slave objects. You supplied %d.", numslaves);
1101 slave_filename[0] = "!!dummy!!";
1102 slave_name[0] = "!!dummy!!";
1103 slave_isframe[0] = 0;
1106 if (config.alloctest)
1108 char*bitmap = malloc(sizeof(char)*65536);
1109 memset(bitmap, 0, 65536*sizeof(char));
1110 memset(bitmap, 1, 101*sizeof(char));
1111 swf_Relocate(&master, bitmap);
1114 // makestackmaster(&newswf);
1121 logf("<error> You must have at least two objects.");
1123 logf("<error> You must have at least one slave entity.");
1126 for(t = 0; t < numslaves; t++)
1128 config.movex = slave_movex[t];
1129 config.movey = slave_movey[t];
1130 config.scalex = slave_scalex[t];
1131 config.scaley = slave_scaley[t];
1132 config.isframe = slave_isframe[t];
1134 logf("<notice> Combine [%s]%s and [%s]%s", master_name, master_filename,
1135 slave_name[t], slave_filename[t]);
1139 fi = open(slave_filename[t], O_RDONLY);
1141 logf("<fatal> Failed to open %s\n", slave_filename[t]);
1144 ret = swf_ReadSWF(fi, &slave);
1146 logf("<fatal> Failed to read from %s\n", slave_filename[t]);
1149 logf("<debug> Read %d bytes from slavefile\n", ret);
1154 memset(&slave, 0, sizeof(slave));
1155 slave.firstTag = swf_InsertTag(0, ST_END);
1156 slave.frameRate = 0;
1157 slave.fileVersion = 4;
1158 slave.frameCount = 0;
1161 combine(&master, slave_name[t], &slave, &newswf);
1166 fi = open(outputname, O_RDWR|O_TRUNC|O_CREAT, 0777);
1169 swf_WriteSWC(fi, &newswf);
1171 newswf.compressed = 0;
1172 swf_WriteSWF(fi, &newswf);