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"))
136 config.framerate = atoi(val)*256/100;
139 else if (!strcmp(name, "X"))
141 config.sizex = atoi(val)*20;
145 else if (!strcmp(name, "Y"))
147 config.sizey = atoi(val)*20;
151 else if (!strcmp(name, "s"))
153 config.scalex = config.scaley = atoi(val)/100.0;
156 else if (!strcmp(name, "t") || !strcmp(name, "T"))
158 if(master_filename) {
159 fprintf(stderr, "error with arguments. Try --help.\n");
163 if(!strcmp(name,"T"))
165 master_filename = "__none__";
168 else if (!strcmp(name, "V"))
170 printf("swfcombine - part of %s %s\n", PACKAGE, VERSION);
175 fprintf(stderr, "Unknown option: -%s\n", name);
180 struct options_t options[] =
202 int args_callback_longoption(char*name,char*val) {
203 return args_long2shortoption(options, name, val);
206 int args_callback_command(char*name, char*val) {
207 char*myname = strdup(name);
209 filename = strchr(myname, '=');
214 // argument has no explicit name field. guess one from the file name
215 char*path = strrchr(myname, '/');
216 char*ext = strrchr(myname, '.');
217 if(!path) path = myname;
224 if(!master_filename) {
225 master_filename = filename;
226 master_name = myname;
227 config.mastermovex = config.movex;
228 config.mastermovey = config.movey;
229 config.masterscalex = config.scalex;
230 config.masterscaley = config.scaley;
231 config.movex = config.movey = 0;
232 config.scalex = config.scaley = 1.0;
234 msg("<verbose> slave entity %s (named \"%s\")\n", filename, myname);
236 slave_filename[numslaves] = filename;
237 slave_name[numslaves] = myname;
238 slave_movex[numslaves] = config.movex;
239 slave_movey[numslaves] = config.movey;
240 slave_scalex[numslaves] = config.scalex;
241 slave_scaley[numslaves] = config.scaley;
242 slave_isframe[numslaves] = config.isframe;
244 config.movex = config.movey = 0;
245 config.scalex = config.scaley = 1.0;
251 void args_callback_usage(char*name)
253 printf("Usage: %s [-rXYomlcv] [-f] masterfile [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
254 printf("OR: %s [-rXYomv] --stack[1] [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
255 printf("OR: %s [-rXYov] --cat [-xysf] [(name1|#id1)=]slavefile1 .. [-xysf] [(nameN|#idN)=]slavefileN\n", name);
256 printf("OR: %s [-rXYomlcv] --dummy [-xys] [file]\n", name);
258 printf("-o outputfile --output explicitly specify output file. (otherwise, output.swf will be used)\n");
259 printf("-t --stack place each slave in a seperate frame (no master movie)\n");
260 printf("-T --stack1 place each slave in the first frame (no master movie)\n");
261 printf("-m --merge Don't store the slaves in Sprites/MovieClips\n");
262 printf("-a --cat concatenate all slave files (no master movie)\n");
263 printf("-l --overlay Don't remove any master objects, only overlay new objects\n");
264 printf("-c --clip Clip the slave objects by the corresponding master objects\n");
265 printf("-v --verbose Use more than one -v for greater effect \n");
266 printf("-d --dummy Don't require slave objects \n");
267 printf("-f --frame The following identifier is a frame or framelabel, not an id or objectname\n");
268 printf("-x xpos --movex x Adjust position of slave by xpos twips (1/20 pixel)\n");
269 printf("-y ypos --movey y Adjust position of slave by ypos twips (1/20 pixel)\n");
270 printf("-s scale --scale Adjust size of slave by scale%\n");
271 printf("-r framerate --rate Set movie framerate (100 frames/sec)\n");
272 printf("-X width --width Force movie width to scale (default: use master width (not with -t))\n");
273 printf("-Y height --height Force movie height to scale (default: use master height (not with -t))\n");
274 printf("-z zlib --zlib Enable Flash 6 (MX) Zlib Compression\n");
277 static void makestackmaster(SWF*swf)
286 memset(&box, 0, sizeof(box));
288 /* scan all slaves for bounding box */
289 for(t=numslaves-1;t>=0;t--)
293 int fi=open(slave_filename[t],O_RDONLY|O_BINARY);
295 if(fi<0 || swf_ReadSWF(fi, &head)<0) {
296 msg("<fatal> Couldn't open/read %s.", slave_filename[t]);
300 msg("<verbose> File %s has bounding box %d:%d:%d:%d\n",
302 head.movieSize.xmin, head.movieSize.ymin,
303 head.movieSize.xmax, head.movieSize.ymax);
307 if(tag->id == ST_SETBACKGROUNDCOLOR && tag->len>=3) {
308 rgb.r = tag->data[0];
309 rgb.g = tag->data[1];
310 rgb.b = tag->data[2];
314 frameRate = head.frameRate;
315 if(head.fileVersion > fileversion)
316 fileversion = head.fileVersion;
318 box = head.movieSize;
320 if(head.movieSize.xmin < box.xmin)
321 box.xmin = head.movieSize.xmin;
322 if(head.movieSize.ymin < box.ymin)
323 box.ymin = head.movieSize.ymin;
324 if(head.movieSize.xmax > box.xmax)
325 box.xmax = head.movieSize.xmax;
326 if(head.movieSize.ymax > box.ymax)
327 box.ymax = head.movieSize.ymax;
329 msg("<verbose> New master bounding box is %d:%d:%d:%d\n",
335 memset(swf, 0, sizeof(SWF));
336 swf->fileVersion = fileversion;
337 swf->movieSize = box;
338 swf->frameRate = frameRate;
340 swf->firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
342 swf_SetRGB(tag, &rgb);
344 for(t=0;t<numslaves;t++)
347 sprintf(buf, "Frame%02d", t);
348 slave_name[t] = strdup(buf);
350 tag = swf_InsertTag(tag, ST_DEFINESPRITE);
351 swf_SetU16(tag, t+1);
353 tag = swf_InsertTag(tag, ST_END);
354 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
355 swf_ObjectPlace(tag, t+1, 1+t,0,0, slave_name[t]);
357 if(!config.stack1 || t == numslaves-1) {
358 tag = swf_InsertTag(tag, ST_SHOWFRAME);
363 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
364 swf_SetU16(tag, 1+t);
367 tag = swf_InsertTag(tag, ST_END);
368 msg("<verbose> temporary SWF created");
371 static char* slavename = 0;
372 static int slaveid = -1;
373 static int slaveframe = -1;
374 static char masterbitmap[65536];
376 #define FLAGS_WRITEDEFINES 1
377 #define FLAGS_WRITENONDEFINES 2
378 #define FLAGS_WRITESPRITE 4
379 #define FLAGS_WRITESLAVE 8
381 int get_free_id(char*bitmap)
392 void jpeg_assert(SWF*master, SWF*slave)
394 /* TODO: if there's a jpegtable found, store it
395 and handle it together with the flash file
398 /* check that master and slave don't have both
399 jpegtables (which would be fatal) */
401 TAG *mpos=0, *spos=0;
404 mtag = master->firstTag;
405 stag = slave->firstTag;
408 if(mtag->id == ST_JPEGTABLES)
414 if(stag->id == ST_JPEGTABLES)
420 if(spos->len == mpos->len &&
421 !memcmp(spos->data, mpos->data, mpos->len))
423 // ok, both have jpegtables, but they're identical.
424 // delete one and don't throw an error
430 msg("<error> Master and slave have incompatible JPEGTABLES.");
434 TAG* write_sprite_defines(TAG*tag, SWF*sprite)
436 TAG*rtag = sprite->firstTag;
437 while(rtag && rtag->id!=ST_END) {
438 if(!swf_isAllowedSpriteTag(rtag)) {
439 msg("<debug> processing sprite tag %02x", tag->id);
440 if(swf_isDefiningTag(rtag))
442 msg("<debug> [sprite defs] write tag %02x (%d bytes in body)",
444 tag = swf_InsertTag(tag, rtag->id);
445 swf_SetBlock(tag, rtag->data, rtag->len);
447 else if(swf_isPseudoDefiningTag(rtag))
449 msg("<debug> [sprite defs] write tag %02x (%d bytes in body)",
451 tag = swf_InsertTag(tag, rtag->id);
452 swf_SetBlock(tag, rtag->data, rtag->len);
458 /* if we get here, jpeg_assert has already run,
459 ensuring this is the only one of it's kind,
460 so we may safely write it out */
461 tag = swf_InsertTag(tag, rtag->id);
462 swf_SetBlock(tag, rtag->data, rtag->len);
464 case ST_EXPORTASSETS:
465 msg("<debug> deliberately ignoring EXPORTASSETS tag");
467 case ST_ENABLEDEBUGGER:
468 msg("<debug> deliberately ignoring ENABLEDEBUGGER tag");
470 case ST_SETBACKGROUNDCOLOR:
471 msg("<debug> deliberately ignoring BACKGROUNDCOLOR tag");
476 msg("<notice> found tag %d. This is a Generator template, isn't it?", tag->id);
479 msg("<notice> funny tag: %d is neither defining nor sprite", tag->id);
488 void changedepth(TAG*tag, int add)
490 /* fucking byteorders */
491 if(tag->id == ST_PLACEOBJECT)
492 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
493 if(tag->id == ST_PLACEOBJECT2)
494 PUT16(&tag->data[1],GET16(&tag->data[1])+add);
495 if(tag->id == ST_REMOVEOBJECT)
496 PUT16(&tag->data[2],GET16(&tag->data[2])+add);
497 if(tag->id == ST_REMOVEOBJECT2)
498 PUT16(&tag->data[0],GET16(&tag->data[0])+add);
501 void matrix_adjust(MATRIX*m, int movex, int movey, float scalex, float scaley, int scalepos)
503 m->sx = (int)(m->sx*scalex);
504 m->sy = (int)(m->sy*scaley);
505 m->r1 = (int)(m->r1*scalex);
506 m->r0 = (int)(m->r0*scaley);
515 void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, float scaley, int scalepos)
517 if(movex || movey || scalex != 1 || scaley != 1)
521 case ST_PLACEOBJECT2: {
524 swf_GetMatrix(0, &m);
528 flags = swf_GetU8(tag);
529 swf_SetU8(output, flags|4);
530 swf_SetU16(output, swf_GetU16(tag)); //depth
533 swf_SetU16(output, swf_GetU16(tag)); //id
537 swf_GetMatrix(tag, &m);
539 swf_GetMatrix(0, &m);
541 matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
542 swf_SetMatrix(output, &m);
544 //swf_ResetReadBits(tag);
545 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
548 case ST_PLACEOBJECT: {
550 swf_SetU16(output, swf_GetU16(tag)); //id
551 swf_SetU16(output, swf_GetU16(tag)); //depth
553 swf_GetMatrix(tag, &m);
554 matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
555 swf_SetMatrix(output, &m);
557 //swf_ResetReadBits(tag);
558 swf_SetBlock(output, &tag->data[tag->pos], tag->len - tag->pos);
562 swf_SetBlock(output, tag->data, tag->len);
567 swf_SetBlock(output, tag->data, tag->len);
571 TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
573 TAG* definespritetag;
577 definespritetag = tag = swf_InsertTag(tag, ST_DEFINESPRITE);
578 swf_SetU16(tag, spriteid);
579 swf_SetU16(tag, sprite->frameCount);
580 msg ("<notice> sprite id is %d", spriteid);
582 tmp = sprite->frameCount;
583 msg("<debug> %d frames to go",tmp);
586 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
587 swf_SetU8(tag, 2+64); //flags: character+clipdepth
588 swf_SetU16(tag, 0); //depth
589 swf_SetU16(tag, replaceddefine); //id
590 swf_SetU16(tag, 65535); //clipdepth
593 if(config.overlay && !config.isframe) {
594 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
595 swf_SetU8(tag, 2); //flags: character
596 swf_SetU16(tag, 1); //depth
597 swf_SetU16(tag, replaceddefine); //id
600 rtag = sprite->firstTag;
601 while(rtag && rtag->id!=ST_END)
603 if (swf_isAllowedSpriteTag(rtag)) {
605 msg("<debug> [sprite main] write tag %02x (%d bytes in body)",
606 rtag->id, rtag->len);
607 tag = swf_InsertTag(tag, rtag->id);
608 write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley, 0);
610 changedepth(tag, +2);
612 if(tag->id == ST_SHOWFRAME)
615 msg("<debug> %d frames to go",tmp);
620 tag = swf_InsertTag(tag, ST_END);
624 static char tag_ok_for_slave(int id)
626 if(id == ST_SETBACKGROUNDCOLOR)
631 TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefine, int flags)
636 int slavewritten = 0;
638 TAG* rtag = master->firstTag;
639 TAG* stag = slave->firstTag;
641 while(rtag && rtag->id!=ST_END)
643 if(rtag->id == ST_SHOWFRAME && outputslave)
645 while(stag && stag->id!=ST_END) {
646 if(stag->id == ST_SHOWFRAME) {
651 if(tag_ok_for_slave(stag->id)) {
652 tag = swf_InsertTag(tag, stag->id);
653 swf_SetBlock(tag, stag->data, stag->len);
658 if(rtag->id == ST_SHOWFRAME)
663 if(swf_isDefiningTag(rtag) && (flags&FLAGS_WRITEDEFINES))
665 msg("<debug> [master] write tag %02x (%d bytes in body)",
666 rtag->id, rtag->len);
667 if(swf_GetDefineID(rtag) == spriteid && !config.isframe)
671 tag = swf_InsertTag(tag, rtag->id);
672 swf_SetBlock(tag, rtag->data, rtag->len);
673 swf_SetDefineID(tag, replaceddefine);
675 /* don't write this tag */
676 msg("<verbose> replacing tag %d id %d with sprite", rtag->id
680 if(flags&FLAGS_WRITESPRITE)
682 tag = write_sprite_defines(tag, slave);
683 tag = write_sprite(tag, slave, spriteid, replaceddefine);
685 if(flags&FLAGS_WRITESLAVE)
690 tag = swf_InsertTag(tag, rtag->id);
691 swf_SetBlock(tag, rtag->data, rtag->len);
694 if(frame == slaveframe)
696 if(flags&FLAGS_WRITESLAVE) {
700 if((flags&FLAGS_WRITESPRITE) && !slavewritten)
702 int id = get_free_id(masterbitmap);
705 msg("<fatal> Can't combine --clip and --frame");
708 tag = write_sprite_defines(tag, slave);
709 tag = write_sprite(tag, slave, id, -1);
711 tag = swf_InsertTag(tag, ST_PLACEOBJECT2);
712 swf_SetU8(tag, 2); //flags: id
713 swf_SetU16(tag, depth);
719 if(!swf_isDefiningTag(rtag) && (flags&FLAGS_WRITENONDEFINES))
724 case ST_PLACEOBJECT2:
725 if(frame == slaveframe && !config.overlay)
727 case ST_REMOVEOBJECT:
728 /* place/removetags for the object we replaced
729 should be discarded, too, as the object to insert
732 if(spriteid>=0 && swf_GetPlaceID(rtag) == spriteid &&
733 !config.isframe && config.merge)
736 case ST_REMOVEOBJECT2:
740 msg("<debug> [master] write tag %02x (%d bytes in body)",
741 rtag->id, rtag->len);
742 tag = swf_InsertTag(tag, rtag->id);
743 write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley, 1);
750 while(stag && stag->id!=ST_END)
752 if(tag_ok_for_slave(stag->id)) {
753 tag = swf_InsertTag(tag, stag->id);
754 swf_SetBlock(tag, stag->data, stag->len);
758 if(!slavewritten && config.isframe && (flags&(FLAGS_WRITESLAVE|FLAGS_WRITESPRITE)))
761 msg("<warning> Frame %d doesn't exist in file. No substitution will occur",
764 msg("<warning> Frame \"%s\" doesn't exist in file. No substitution will occur",
767 tag = swf_InsertTag(tag, ST_END);
771 void adjustheader(SWF*swf)
774 swf->frameRate = config.framerate;
775 if(config.hassizex) {
776 swf->movieSize.xmax =
777 swf->movieSize.xmin + config.sizex;
779 if(config.hassizey) {
780 swf->movieSize.ymax =
781 swf->movieSize.ymin + config.sizey;
785 void catcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
792 msg("<fatal> Can't combine --cat and --frame");
796 tag = master->firstTag;
799 if(swf_isDefiningTag(tag)) {
800 int defineid = swf_GetDefineID(tag);
801 msg("<debug> tagid %02x defines object %d", tag->id, defineid);
802 masterbitmap[defineid] = 1;
807 swf_Relocate(slave, masterbitmap);
808 jpeg_assert(master, slave);
810 memcpy(newswf, master, sizeof(SWF));
811 adjustheader(newswf);
813 tag = newswf->firstTag = swf_InsertTag(0, ST_REFLEX); // to be removed later
815 depths = malloc(65536);
817 msg("<fatal> Couldn't allocate %d bytes of memory", 65536);
820 memset(depths, 0, 65536);
821 mtag = master->firstTag;
822 while(mtag && mtag->id!=ST_END)
826 msg("<debug> [master] write tag %02x (%d bytes in body)",
827 mtag->id, mtag->len);
829 case ST_PLACEOBJECT2:
831 case ST_PLACEOBJECT: {
832 depth = swf_GetDepth(mtag);
836 case ST_REMOVEOBJECT: {
837 depth = swf_GetDepth(mtag);
841 case ST_REMOVEOBJECT2: {
842 depth = swf_GetDepth(mtag);
847 tag = swf_InsertTag(tag, mtag->id);
848 swf_SetBlock(tag, mtag->data, mtag->len);
858 tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
863 stag = slave->firstTag;
864 while(stag && stag->id!=ST_END)
866 msg("<debug> [slave] write tag %02x (%d bytes in body)",
867 stag->id, stag->len);
868 tag = swf_InsertTag(tag, stag->id);
869 swf_SetBlock(tag, stag->data, stag->len);
872 tag = swf_InsertTag(tag, ST_END);
874 tag = newswf->firstTag;
875 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
879 void normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
882 int replaceddefine = -1;
885 TAG * tag = master->firstTag;
890 if(swf_isDefiningTag(tag)) {
891 int defineid = swf_GetDefineID(tag);
892 msg("<debug> tagid %02x defines object %d", tag->id, defineid);
893 masterbitmap[defineid] = 1;
894 if (!slavename && defineid==slaveid) {
897 msg("<notice> Slave file attached to object %d.", defineid);
900 } else if(tag->id == ST_PLACEOBJECT2) {
901 char * name = swf_GetName(tag);
902 int id = swf_GetPlaceID(tag);
905 msg("<verbose> tagid %02x places object %d named \"%s\"", tag->id, id, name);
907 msg("<verbose> tagid %02x places object %d (no name)", tag->id, id);
909 if (name && slavename && !strcmp(name,slavename)) {
912 msg("<notice> Slave file attached to named object %s (%d).", name, id);
915 } else if(tag->id == ST_SHOWFRAME) {
916 if(slaveframe>=0 && frame==slaveframe) {
917 msg("<notice> Slave file attached to frame %d.", frame);
920 } else if(tag->id == ST_FRAMELABEL) {
921 char * name = tag->data;
922 if(name && slavename && config.isframe && !strcmp(name, slavename)) {
924 msg("<notice> Slave file attached to frame %d (%s).", frame, name);
930 if (spriteid<0 && !config.isframe) {
932 if(strcmp(slavename,"!!dummy!!"))
933 msg("<warning> Didn't find anything named %s in file. No substitutions will occur.", slavename);
936 msg("<warning> Didn't find id %d in file. No substitutions will occur.", slaveid);
937 spriteid = get_free_id(masterbitmap);
940 swf_Relocate (slave, masterbitmap);
941 jpeg_assert(slave, master);
944 replaceddefine = get_free_id(masterbitmap);
948 memcpy(newswf, master, sizeof(SWF));
949 adjustheader(newswf);
951 newswf->firstTag = tag = swf_InsertTag(0, ST_REFLEX); // to be removed later
953 if (config.antistream) {
955 msg("<fatal> Can't combine --antistream and --merge");
957 tag = write_sprite_defines(tag, slave);
958 tag = write_sprite(tag, slave, spriteid, replaceddefine);
959 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITEDEFINES);
960 tag = write_master(tag, master, slave, spriteid, replaceddefine, FLAGS_WRITENONDEFINES);
963 tag = write_master(tag, master, slave, spriteid, replaceddefine,
964 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESLAVE );
966 tag = write_master(tag, master, slave, spriteid, replaceddefine,
967 FLAGS_WRITEDEFINES|FLAGS_WRITENONDEFINES| FLAGS_WRITESPRITE );
970 tag = newswf->firstTag;
971 newswf->firstTag = newswf->firstTag->next; //remove temporary tag
975 void combine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
977 slavename = slave_name;
984 if(slavename[0] == '#')
986 slaveid = atoi(&slavename[1]);
993 if(slavename && slavename[0]!='#' && (sscanf(slavename, "%d", &tmp) ==
994 strlen(slavename))) {
995 /* if the name the slave should replace
996 consists only of digits and the -f
997 option is given, it probably is not
998 a frame name but a frame number.
1005 slaveframe = slaveid;
1008 /* if id wasn't given as either #number or number,
1009 the name is a frame label. BTW: The user wouldn't necessarily have
1010 needed to supply the -f option in this case */
1014 msg("<debug> move x (%d)", config.movex);
1015 msg("<debug> move y (%d)", config.movey);
1016 msg("<debug> scale x (%f)", config.scalex);
1017 msg("<debug> scale y (%f)", config.scaley);
1018 msg("<debug> master move x (%d)", config.mastermovex);
1019 msg("<debug> master move y (%d)", config.mastermovey);
1020 msg("<debug> master scale x (%f)", config.masterscalex);
1021 msg("<debug> master scale y (%f)", config.masterscaley);
1022 msg("<debug> is frame (%d)", config.isframe);
1024 memset(masterbitmap, 0, sizeof(masterbitmap));
1027 return catcombine(master, slave_name, slave, newswf);
1029 return normalcombine(master, slave_name, slave, newswf);
1032 int main(int argn, char *argv[])
1041 config.antistream = 0;
1042 config.alloctest = 0;
1046 config.loglevel = 2;
1049 config.scalex = 1.0;
1050 config.scaley = 1.0;
1053 config.masterscalex = 1.0;
1054 config.masterscaley = 1.0;
1055 config.mastermovex = 0;
1056 config.mastermovey = 0;
1057 config.hassizex = 0;
1058 config.hassizey = 0;
1059 config.framerate = 0;
1065 processargs(argn, argv);
1066 initLog(0,-1,0,0,-1,config.loglevel);
1068 if(config.merge && config.cat) {
1069 msg("<error> Can't combine --cat and --merge");
1074 if(config.overlay) {
1075 msg("<error> Can't combine -l and -t");
1079 msg("<error> Can't combine -c and -t");
1082 msg("<verbose> (stacking) %d files found\n", numslaves);
1084 makestackmaster(&master);
1088 msg("<verbose> master entity %s (named \"%s\")\n", master_filename, master_name);
1089 fi = open(master_filename, O_RDONLY|O_BINARY);
1091 msg("<fatal> Failed to open %s\n", master_filename);
1094 ret = swf_ReadSWF(fi, &master);
1096 msg("<fatal> Failed to read from %s\n", master_filename);
1099 msg("<debug> Read %d bytes from masterfile\n", ret);
1103 for(t=0;t<numslaves;t++) {
1104 msg("<verbose> slave entity(%d) %s (%s \"%s\")\n", t+1, slave_filename[t],
1105 slave_isframe[t]?"frame":"object", slave_name[t]);
1112 msg("<error> --dummy (-d) implies there are zero slave objects. You supplied %d.", numslaves);
1116 slave_filename[0] = "!!dummy!!";
1117 slave_name[0] = "!!dummy!!";
1118 slave_isframe[0] = 0;
1121 if (config.alloctest)
1123 char*bitmap = malloc(sizeof(char)*65536);
1124 memset(bitmap, 0, 65536*sizeof(char));
1125 memset(bitmap, 1, 101*sizeof(char));
1126 swf_Relocate(&master, bitmap);
1129 // makestackmaster(&newswf);
1136 msg("<error> You must have at least two objects.");
1138 msg("<error> You must have at least one slave entity.");
1141 for(t = 0; t < numslaves; t++)
1143 config.movex = slave_movex[t];
1144 config.movey = slave_movey[t];
1145 config.scalex = slave_scalex[t];
1146 config.scaley = slave_scaley[t];
1147 config.isframe = slave_isframe[t];
1149 msg("<notice> Combine [%s]%s and [%s]%s", master_name, master_filename,
1150 slave_name[t], slave_filename[t]);
1154 fi = open(slave_filename[t], O_RDONLY|O_BINARY);
1156 msg("<fatal> Failed to open %s\n", slave_filename[t]);
1159 ret = swf_ReadSWF(fi, &slave);
1161 msg("<fatal> Failed to read from %s\n", slave_filename[t]);
1164 msg("<debug> Read %d bytes from slavefile\n", ret);
1169 memset(&slave, 0, sizeof(slave));
1170 slave.firstTag = swf_InsertTag(0, ST_END);
1171 slave.frameRate = 0;
1172 slave.fileVersion = 4;
1173 slave.frameCount = 0;
1176 combine(&master, slave_name[t], &slave, &newswf);
1181 fi = open(outputname, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);
1184 swf_WriteSWC(fi, &newswf);
1186 newswf.compressed = 0;
1187 swf_WriteSWF(fi, &newswf);