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 */
13 #include "../lib/rfxswf.h"
14 #include "../lib/args.h"
15 #include "../lib/log.h"
16 #include "../config.h"
46 struct config_t config;
48 char * master_filename = 0;
49 char * master_name = 0;
50 char * slave_filename[128];
51 char * slave_name[128];
54 float slave_scalex[128];
55 float slave_scaley[128];
56 char slave_isframe[128];
59 char * outputname = "output.swf";
61 int args_callback_option(char*name,char*val) {
67 else if(!strcmp(name,"l"))
72 else if (!strcmp(name, "o"))
77 else if (!strcmp(name, "v"))
82 else if (!strcmp(name, "a"))
87 else if (!strcmp(name, "A"))
92 else if (!strcmp(name, "x"))
94 config.movex = atoi(val);
97 else if (!strcmp(name, "y"))
99 config.movey = atoi(val);
102 else if (!strcmp(name, "m"))
107 else if (!strcmp(name, "f"))
112 else if (!strcmp(name, "d"))
117 else if (!strcmp(name, "z"))
122 else if (!strcmp(name, "r"))
124 config.framerate = atoi(val)*256/100;
127 else if (!strcmp(name, "X"))
129 config.sizex = atoi(val)*20;
133 else if (!strcmp(name, "Y"))
135 config.sizey = atoi(val)*20;
139 else if (!strcmp(name, "s"))
141 config.scalex = config.scaley = atoi(val)/100.0;
144 else if (!strcmp(name, "t") || !strcmp(name, "T"))
146 if(master_filename) {
147 fprintf(stderr, "error with arguments. Try --help.\n");
151 if(!strcmp(name,"T"))
153 master_filename = "__none__";
156 else if (!strcmp(name, "V"))
158 printf("swfcombine - part of %s %s\n", PACKAGE, VERSION);
163 fprintf(stderr, "Unknown option: -%s\n", name);
168 struct options_t options[] =
190 int args_callback_longoption(char*name,char*val) {
191 return args_long2shortoption(options, name, val);
194 int args_callback_command(char*name, char*val) {
195 char*myname = strdup(name);
197 filename = strchr(myname, '=');
202 // argument has no explicit name field. guess one from the file name
203 char*path = strrchr(myname, '/');
204 char*ext = strrchr(myname, '.');
205 if(!path) path = myname;
212 if(!master_filename) {
213 master_filename = filename;
214 master_name = myname;
215 config.mastermovex = config.movex;
216 config.mastermovey = config.movey;
217 config.masterscalex = config.scalex;
218 config.masterscaley = config.scaley;
219 config.movex = config.movey = 0;
220 config.scalex = config.scaley = 1.0;
222 msg("<verbose> slave entity %s (named \"%s\")\n", filename, myname);
224 slave_filename[numslaves] = filename;
225 slave_name[numslaves] = myname;
226 slave_movex[numslaves] = config.movex;
227 slave_movey[numslaves] = config.movey;
228 slave_scalex[numslaves] = config.scalex;
229 slave_scaley[numslaves] = config.scaley;
230 slave_isframe[numslaves] = config.isframe;
232 config.movex = config.movey = 0;
233 config.scalex = config.scaley = 1.0;
239 void args_callback_usage(char*name)
241 printf("Usage: %s [-rXYomlcv] [-f] masterfile [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
242 printf("OR: %s [-rXYomv] --stack[1] [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
243 printf("OR: %s [-rXYov] --cat [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
244 printf("OR: %s [-rXYomlcv] --dummy [-xys] [file]\n", name);
246 printf("-o outputfile --output explicitly specify output file. (otherwise, output.swf will be used)\n");
247 printf("-t --stack place each slave in a seperate frame (no master movie)\n");
248 printf("-T --stack1 place each slave in the first frame (no master movie)\n");
249 printf("-m --merge Don't store the slaves in Sprites/MovieClips\n");
250 printf("-a --cat concatenate all slave files (no master movie)\n");
251 printf("-l --overlay Don't remove any master objects, only overlay new objects\n");
252 printf("-c --clip Clip the slave objects by the corresponding master objects\n");
253 printf("-v --verbose Use more than one -v for greater effect \n");
254 printf("-d --dummy Don't require slave objects \n");
255 printf("-f --frame The following identifier is a frame or framelabel, not an id or objectname\n");
256 printf("-x xpos --movex x Adjust position of slave by xpos twips (1/20 pixel)\n");
257 printf("-y ypos --movey y Adjust position of slave by ypos twips (1/20 pixel)\n");
258 printf("-s scale --scale Adjust size of slave by scale%\n");
259 printf("-r framerate --rate Set movie framerate (100 frames/sec)\n");
260 printf("-X width --width Force movie width to scale (default: use master width (not with -t))\n");
261 printf("-Y height --height Force movie height to scale (default: use master height (not with -t))\n");
262 printf("-z zlib --zlib Enable Flash 6 (MX) Zlib Compression\n");
265 static void makestackmaster(SWF*swf)
274 memset(&box, 0, sizeof(box));
276 /* scan all slaves for bounding box */
277 for(t=numslaves-1;t>=0;t--)
281 int fi=open(slave_filename[t],O_RDONLY|O_BINARY);
283 if(fi<0 || swf_ReadSWF(fi, &head)<0) {
284 msg("<fatal> Couldn't open/read %s.", slave_filename[t]);
288 msg("<verbose> File %s has bounding box %d:%d:%d:%d\n",
290 head.movieSize.xmin, head.movieSize.ymin,
291 head.movieSize.xmax, head.movieSize.ymax);
295 if(tag->id == ST_SETBACKGROUNDCOLOR && tag->len>=3) {
296 rgb.r = tag->data[0];
297 rgb.g = tag->data[1];
298 rgb.b = tag->data[2];
302 frameRate = head.frameRate;
303 if(head.fileVersion > fileversion)
304 fileversion = head.fileVersion;
306 box = head.movieSize;
308 if(head.movieSize.xmin < box.xmin)
309 box.xmin = head.movieSize.xmin;
310 if(head.movieSize.ymin < box.ymin)
311 box.ymin = head.movieSize.ymin;
312 if(head.movieSize.xmax > box.xmax)
313 box.xmax = head.movieSize.xmax;
314 if(head.movieSize.ymax > box.ymax)
315 box.ymax = head.movieSize.ymax;
317 msg("<verbose> New master bounding box is %d:%d:%d:%d\n",
323 memset(swf, 0, sizeof(SWF));
324 swf->fileVersion = fileversion;
325 swf->movieSize = box;
326 swf->frameRate = frameRate;
328 swf->firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
330 swf_SetRGB(tag, &rgb);
332 for(t=0;t<numslaves;t++)
335 sprintf(buf, "Frame%02d", t);
336 slave_name[t] = strdup(buf);
338 tag = swf_InsertTag(tag, ST_DEFINESPRITE);
339 swf_SetU16(tag, t+1);
341 tag = swf_InsertTag(tag, ST_END);
342 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
343 swf_ObjectPlace(tag, t+1, 1+t,0,0, slave_name[t]);
345 if(!config.stack1 || t == numslaves-1) {
346 tag = swf_InsertTag(tag, ST_SHOWFRAME);
351 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
352 swf_SetU16(tag, 1+t);
355 tag = swf_InsertTag(tag, ST_END);
356 msg("<verbose> temporary SWF created");
359 static char* slavename = 0;
360 static int slaveid = -1;
361 static int slaveframe = -1;
362 static char masterbitmap[65536];
364 #define FLAGS_WRITEDEFINES 1
365 #define FLAGS_WRITENONDEFINES 2
366 #define FLAGS_WRITESPRITE 4
367 #define FLAGS_WRITESLAVE 8
369 int get_free_id(char*bitmap)
380 void jpeg_assert(SWF*master, SWF*slave)
382 /* TODO: if there's a jpegtable found, store it
383 and handle it together with the flash file
386 /* check that master and slave don't have both
387 jpegtables (which would be fatal) */
389 TAG *mpos=0, *spos=0;
392 mtag = master->firstTag;
393 stag = slave->firstTag;
396 if(mtag->id == ST_JPEGTABLES)
402 if(stag->id == ST_JPEGTABLES)
408 if(spos->len == mpos->len &&
409 !memcmp(spos->data, mpos->data, mpos->len))
411 // ok, both have jpegtables, but they're identical.
412 // delete one and don't throw an error
418 msg("<error> Master and slave have incompatible JPEGTABLES.");
422 TAG* write_sprite_defines(TAG*tag, SWF*sprite)
424 TAG*rtag = sprite->firstTag;
425 while(rtag && rtag->id!=ST_END) {
426 if(!swf_isAllowedSpriteTag(rtag)) {
427 msg("<debug> processing sprite tag %02x", tag->id);
428 if(swf_isDefiningTag(rtag))
430 msg("<debug> [sprite defs] write tag %02x (%d bytes in body)",
432 tag = swf_InsertTag(tag, rtag->id);
433 swf_SetBlock(tag, rtag->data, rtag->len);
435 else if(swf_isPseudoDefiningTag(rtag))
437 msg("<debug> [sprite defs] write tag %02x (%d bytes in body)",
439 tag = swf_InsertTag(tag, rtag->id);
440 swf_SetBlock(tag, rtag->data, rtag->len);
446 /* if we get here, jpeg_assert has already run,
447 ensuring this is the only one of it's kind,
448 so we may safely write it out */
449 tag = swf_InsertTag(tag, rtag->id);
450 swf_SetBlock(tag, rtag->data, rtag->len);
452 case ST_EXPORTASSETS:
453 msg("<debug> deliberately ignoring EXPORTASSETS tag");
455 case ST_ENABLEDEBUGGER:
456 msg("<debug> deliberately ignoring ENABLEDEBUGGER tag");
458 case ST_SETBACKGROUNDCOLOR:
459 msg("<debug> deliberately ignoring BACKGROUNDCOLOR tag");
464 msg("<notice> found tag %d. This is a Generator template, isn't it?", tag->id);
467 msg("<notice> funny tag: %d is neither defining nor sprite", tag->id);
476 void changedepth(TAG*tag, int add)
478 /* fucking byteorders */
479 if(tag->id == ST_PLACEOBJECT)
480 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
481 if(tag->id == ST_PLACEOBJECT2)
482 PUT16(&tag->data[1],GET16(&tag->data[1])+add);
483 if(tag->id == ST_REMOVEOBJECT)
484 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
485 if(tag->id == ST_REMOVEOBJECT2)
486 PUT16(&tag->data[0],GET16(&tag->data[0])+add);
489 void matrix_adjust(MATRIX*m, int movex, int movey, float scalex, float scaley, int scalepos)
491 m->sx = (int)(m->sx*scalex);
492 m->sy = (int)(m->sy*scaley);
493 m->r1 = (int)(m->r1*scalex);
494 m->r0 = (int)(m->r0*scaley);
503 void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, float scaley, int scalepos)
505 if(movex || movey || scalex != 1 || scaley != 1)
509 case ST_PLACEOBJECT2: {
512 swf_GetMatrix(0, &m);
516 flags = swf_GetU8(tag);
517 swf_SetU8(output, flags|4);
518 swf_SetU16(output, swf_GetU16(tag)); //depth
521 swf_SetU16(output, swf_GetU16(tag)); //id
525 swf_GetMatrix(tag, &m);
527 swf_GetMatrix(0, &m);
529 matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
530 swf_SetMatrix(output, &m);
532 //swf_ResetReadBits(tag);
533 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
536 case ST_PLACEOBJECT: {
538 swf_SetU16(output, swf_GetU16(tag)); //id
539 swf_SetU16(output, swf_GetU16(tag)); //depth
541 swf_GetMatrix(tag, &m);
542 matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
543 swf_SetMatrix(output, &m);
545 //swf_ResetReadBits(tag);
546 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
550 swf_SetBlock(output, tag->data, tag->len);
555 swf_SetBlock(output, tag->data, tag->len);
559 TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
561 TAG* definespritetag;
565 definespritetag = tag = swf_InsertTag(tag, ST_DEFINESPRITE);
566 swf_SetU16(tag, spriteid);
567 swf_SetU16(tag, sprite->frameCount);
568 msg ("<notice> sprite id is %d", spriteid);
570 tmp = sprite->frameCount;
571 msg("<debug> %d frames to go",tmp);
574 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
575 swf_SetU8(tag, 2+64); //flags: character+clipdepth
576 swf_SetU16(tag, 0); //depth
577 swf_SetU16(tag, replaceddefine); //id
578 swf_SetU16(tag, 65535); //clipdepth
581 if(config.overlay && !config.isframe) {
582 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
583 swf_SetU8(tag, 2); //flags: character
584 swf_SetU16(tag, 1); //depth
585 swf_SetU16(tag, replaceddefine); //id
588 rtag = sprite->firstTag;
589 while(rtag && rtag->id!=ST_END)
591 if (swf_isAllowedSpriteTag(rtag)) {
593 msg("<debug> [sprite main] write tag %02x (%d bytes in body)",
594 rtag->id, rtag->len);
595 tag = swf_InsertTag(tag, rtag->id);
596 write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley, 0);
598 changedepth(tag, +2);
600 if(tag->id == ST_SHOWFRAME)
603 msg("<debug> %d frames to go",tmp);
608 tag = swf_InsertTag(tag, ST_END);
612 static char tag_ok_for_slave(int id)
614 if(id == ST_SETBACKGROUNDCOLOR)
619 TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefine, int flags)
624 int slavewritten = 0;
626 TAG* rtag = master->firstTag;
627 TAG* stag = slave->firstTag;
629 while(rtag && rtag->id!=ST_END)
631 if(rtag->id == ST_SHOWFRAME && outputslave)
633 while(stag && stag->id!=ST_END) {
634 if(stag->id == ST_SHOWFRAME) {
639 if(tag_ok_for_slave(stag->id)) {
640 tag = swf_InsertTag(tag, stag->id);
641 swf_SetBlock(tag, stag->data, stag->len);
646 if(rtag->id == ST_SHOWFRAME)
651 if(swf_isDefiningTag(rtag) && (flags&FLAGS_WRITEDEFINES))
653 msg("<debug> [master] write tag %02x (%d bytes in body)",
654 rtag->id, rtag->len);
655 if(swf_GetDefineID(rtag) == spriteid && !config.isframe)
659 tag = swf_InsertTag(tag, rtag->id);
660 swf_SetBlock(tag, rtag->data, rtag->len);
661 swf_SetDefineID(tag, replaceddefine);
663 /* don't write this tag */
664 msg("<verbose> replacing tag %d id %d with sprite", rtag->id
668 if(flags&FLAGS_WRITESPRITE)
670 tag = write_sprite_defines(tag, slave);
671 tag = write_sprite(tag, slave, spriteid, replaceddefine);
673 if(flags&FLAGS_WRITESLAVE)
678 tag = swf_InsertTag(tag, rtag->id);
679 swf_SetBlock(tag, rtag->data, rtag->len);
682 if(frame == slaveframe)
684 if(flags&FLAGS_WRITESLAVE) {
688 if((flags&FLAGS_WRITESPRITE) && !slavewritten)
690 int id = get_free_id(masterbitmap);
693 msg("<fatal> Can't combine --clip and --frame");
696 tag = write_sprite_defines(tag, slave);
697 tag = write_sprite(tag, slave, id, -1);
699 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
700 swf_SetU8(tag, 2); //flags: id
701 swf_SetU16(tag, depth);
707 if(!swf_isDefiningTag(rtag) && (flags&FLAGS_WRITENONDEFINES))
712 case ST_PLACEOBJECT2:
713 if(frame == slaveframe && !config.overlay)
715 case ST_REMOVEOBJECT:
716 /* place/removetags for the object we replaced
717 should be discarded, too, as the object to insert
720 if(spriteid>=0 && swf_GetPlaceID(rtag) == spriteid &&
721 !config.isframe && config.merge)
724 case ST_REMOVEOBJECT2:
728 msg("<debug> [master] write tag %02x (%d bytes in body)",
729 rtag->id, rtag->len);
730 tag = swf_InsertTag(tag, rtag->id);
731 write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley, 1);
738 while(stag && stag->id!=ST_END)
740 if(tag_ok_for_slave(stag->id)) {
741 tag = swf_InsertTag(tag, stag->id);
742 swf_SetBlock(tag, stag->data, stag->len);
746 if(!slavewritten && config.isframe && (flags&(FLAGS_WRITESLAVE|FLAGS_WRITESPRITE)))
749 msg("<warning> Frame %d doesn't exist in file. No substitution will occur",
752 msg("<warning> Frame \"%s\" doesn't exist in file. No substitution will occur",
755 tag = swf_InsertTag(tag, ST_END);
759 void adjustheader(SWF*swf)
762 swf->frameRate = config.framerate;
763 if(config.hassizex) {
764 swf->movieSize.xmax =
765 swf->movieSize.xmin + config.sizex;
767 if(config.hassizey) {
768 swf->movieSize.ymax =
769 swf->movieSize.ymin + config.sizey;
773 void catcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
780 msg("<fatal> Can't combine --cat and --frame");
784 tag = master->firstTag;
787 if(swf_isDefiningTag(tag)) {
788 int defineid = swf_GetDefineID(tag);
789 msg("<debug> tagid %02x defines object %d", tag->id, defineid);
790 masterbitmap[defineid] = 1;
795 swf_Relocate(slave, masterbitmap);
796 jpeg_assert(master, slave);
798 memcpy(newswf, master, sizeof(SWF));
799 adjustheader(newswf);
801 tag = newswf->firstTag = swf_InsertTag(0, ST_REFLEX); // to be removed later
803 depths = malloc(65536);
805 msg("<fatal> Couldn't allocate %d bytes of memory", 65536);
808 memset(depths, 0, 65536);
809 mtag = master->firstTag;
810 while(mtag && mtag->id!=ST_END)
814 msg("<debug> [master] write tag %02x (%d bytes in body)",
815 mtag->id, mtag->len);
817 case ST_PLACEOBJECT2:
819 case ST_PLACEOBJECT: {
820 depth = swf_GetDepth(mtag);
824 case ST_REMOVEOBJECT: {
825 depth = swf_GetDepth(mtag);
829 case ST_REMOVEOBJECT2: {
830 depth = swf_GetDepth(mtag);
835 tag = swf_InsertTag(tag, mtag->id);
836 swf_SetBlock(tag, mtag->data, mtag->len);
846 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
851 stag = slave->firstTag;
852 while(stag && stag->id!=ST_END)
854 msg("<debug> [slave] write tag %02x (%d bytes in body)",
855 stag->id, stag->len);
856 tag = swf_InsertTag(tag, stag->id);
857 swf_SetBlock(tag, stag->data, stag->len);
860 tag = swf_InsertTag(tag, ST_END);
862 tag = newswf->firstTag;
863 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
867 void normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
870 int replaceddefine = -1;
873 TAG * tag = master->firstTag;
878 if(swf_isDefiningTag(tag)) {
879 int defineid = swf_GetDefineID(tag);
880 msg("<debug> tagid %02x defines object %d", tag->id, defineid);
881 masterbitmap[defineid] = 1;
882 if (!slavename && defineid==slaveid) {
885 msg("<notice> Slave file attached to object %d.", defineid);
888 } else if(tag->id == ST_PLACEOBJECT2) {
889 char * name = swf_GetName(tag);
890 int id = swf_GetPlaceID(tag);
893 msg("<verbose> tagid %02x places object %d named \"%s\"", tag->id, id, name);
895 msg("<verbose> tagid %02x places object %d (no name)", tag->id, id);
897 if (name && slavename && !strcmp(name,slavename)) {
900 msg("<notice> Slave file attached to named object %s (%d).", name, id);
903 } else if(tag->id == ST_SHOWFRAME) {
904 if(slaveframe>=0 && frame==slaveframe) {
905 msg("<notice> Slave file attached to frame %d.", frame);
908 } else if(tag->id == ST_FRAMELABEL) {
909 char * name = tag->data;
910 if(name && slavename && config.isframe && !strcmp(name, slavename)) {
912 msg("<notice> Slave file attached to frame %d (%s).", frame, name);
918 if (spriteid<0 && !config.isframe) {
920 if(strcmp(slavename,"!!dummy!!"))
921 msg("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
924 msg("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
925 spriteid = get_free_id(masterbitmap);
928 swf_Relocate (slave, masterbitmap);
929 jpeg_assert(slave, master);
932 replaceddefine = get_free_id(masterbitmap);
936 memcpy(newswf, master, sizeof(SWF));
937 adjustheader(newswf);
939 newswf->firstTag = tag = swf_InsertTag(0, ST_REFLEX); // to be removed later
941 if (config.antistream) {
943 msg("<fatal> Can't combine --antistream and --merge");
945 tag = write_sprite_defines(tag, slave);
946 tag = write_sprite(tag, slave, spriteid, replaceddefine);
947 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITEDEFINES);
948 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITENONDEFINES);
951 tag = write_master(tag, master, slave, spriteid, replaceddefine,
952 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESLAVE );
954 tag = write_master(tag, master, slave, spriteid, replaceddefine,
955 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESPRITE );
958 tag = newswf->firstTag;
959 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
963 void combine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
965 slavename = slave_name;
972 if(slavename[0] == '#')
974 slaveid = atoi(&slavename[1]);
981 if(slavename && slavename[0]!='#' && (sscanf(slavename, "%d", &tmp) ==
982 strlen(slavename))) {
983 /* if the name the slave should replace
984 consists only of digits and the -f
985 option is given, it probably is not
986 a frame name but a frame number.
993 slaveframe = slaveid;
996 /* if id wasn't given as either #number or number,
997 the name is a frame label. BTW: The user wouldn't necessarily have
998 needed to supply the -f option in this case */
1002 msg("<debug> move x (%d)", config.movex);
1003 msg("<debug> move y (%d)", config.movey);
1004 msg("<debug> scale x (%f)", config.scalex);
1005 msg("<debug> scale y (%f)", config.scaley);
1006 msg("<debug> master move x (%d)", config.mastermovex);
1007 msg("<debug> master move y (%d)", config.mastermovey);
1008 msg("<debug> master scale x (%f)", config.masterscalex);
1009 msg("<debug> master scale y (%f)", config.masterscaley);
1010 msg("<debug> is frame (%d)", config.isframe);
1012 memset(masterbitmap, 0, sizeof(masterbitmap));
1015 return catcombine(master, slave_name, slave, newswf);
1017 return normalcombine(master, slave_name, slave, newswf);
1020 int main(int argn, char *argv[])
1029 config.antistream = 0;
1030 config.alloctest = 0;
1034 config.loglevel = 2;
1037 config.scalex = 1.0;
1038 config.scaley = 1.0;
1041 config.masterscalex = 1.0;
1042 config.masterscaley = 1.0;
1043 config.mastermovex = 0;
1044 config.mastermovey = 0;
1045 config.hassizex = 0;
1046 config.hassizey = 0;
1047 config.framerate = 0;
1053 processargs(argn, argv);
1054 initLog(0,-1,0,0,-1,config.loglevel);
1056 if(config.merge && config.cat) {
1057 msg("<error> Can't combine --cat and --merge");
1062 if(config.overlay) {
1063 msg("<error> Can't combine -l and -t");
1067 msg("<error> Can't combine -c and -t");
1070 msg("<verbose> (stacking) %d files found\n", numslaves);
1072 makestackmaster(&master);
1076 msg("<verbose> master entity %s (named \"%s\")\n", master_filename, master_name);
1077 fi = open(master_filename, O_RDONLY|O_BINARY);
1079 msg("<fatal> Failed to open %s\n", master_filename);
1082 ret = swf_ReadSWF(fi, &master);
1084 msg("<fatal> Failed to read from %s\n", master_filename);
1087 msg("<debug> Read %d bytes from masterfile\n", ret);
1091 for(t=0;t<numslaves;t++) {
1092 msg("<verbose> slave entity(%d) %s (%s \"%s\")\n", t+1, slave_filename[t],
1093 slave_isframe[t]?"frame":"object", slave_name[t]);
1100 msg("<error> --dummy (-d) implies there are zero slave objects. You supplied %d.", numslaves);
1104 slave_filename[0] = "!!dummy!!";
1105 slave_name[0] = "!!dummy!!";
1106 slave_isframe[0] = 0;
1109 if (config.alloctest)
1111 char*bitmap = malloc(sizeof(char)*65536);
1112 memset(bitmap, 0, 65536*sizeof(char));
1113 memset(bitmap, 1, 101*sizeof(char));
1114 swf_Relocate(&master, bitmap);
1117 // makestackmaster(&newswf);
1124 msg("<error> You must have at least two objects.");
1126 msg("<error> You must have at least one slave entity.");
1129 for(t = 0; t < numslaves; t++)
1131 config.movex = slave_movex[t];
1132 config.movey = slave_movey[t];
1133 config.scalex = slave_scalex[t];
1134 config.scaley = slave_scaley[t];
1135 config.isframe = slave_isframe[t];
1137 msg("<notice> Combine [%s]%s and [%s]%s", master_name, master_filename,
1138 slave_name[t], slave_filename[t]);
1142 fi = open(slave_filename[t], O_RDONLY|O_BINARY);
1144 msg("<fatal> Failed to open %s\n", slave_filename[t]);
1147 ret = swf_ReadSWF(fi, &slave);
1149 msg("<fatal> Failed to read from %s\n", slave_filename[t]);
1152 msg("<debug> Read %d bytes from slavefile\n", ret);
1157 memset(&slave, 0, sizeof(slave));
1158 slave.firstTag = swf_InsertTag(0, ST_END);
1159 slave.frameRate = 0;
1160 slave.fileVersion = 4;
1161 slave.frameCount = 0;
1164 combine(&master, slave_name[t], &slave, &newswf);
1169 fi = open(outputname, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);
1172 swf_WriteSWC(fi, &newswf);
1174 newswf.compressed = 0;
1175 swf_WriteSWF(fi, &newswf);