added protection against using both --cat and --stack
[swftools.git] / src / swfcombine.c
index 6fcbe64..8981b1d 100644 (file)
@@ -137,7 +137,7 @@ int args_callback_option(char*name,char*val) {
     {
 
        float rate = atof(val);
-       if ((rate < 1.0/256) ||(rate >= 256.0)) {
+       if ((rate < 0) ||(rate >= 256.0)) {
            fprintf(stderr, "Error: You must specify a valid framerate between 1/256 and 255.\n");
            exit(1);
        }
@@ -306,6 +306,7 @@ static void makestackmaster(SWF*swf)
            exit(1);
        }
        close(fi);
+       swf_RemoveJPEGTables(&head);
        msg("<verbose> File %s has bounding box %d:%d:%d:%d\n",
                slave_filename[t], 
                head.movieSize.xmin, head.movieSize.ymin,
@@ -666,7 +667,7 @@ static char tag_ok_for_slave(int id)
 TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefine, int flags)
 {
     int outputslave = 0;
-    int frame = 0;
+    int frame = 1;
     int sframe = 0;
     int slavewritten = 0;
     int deletedepth = -1;
@@ -694,6 +695,14 @@ TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefi
        if(rtag->id == ST_SHOWFRAME)
        {
            frame ++;
+           tag = swf_InsertTag(tag, ST_SHOWFRAME);
+            if(deletedepth>=0) {
+                tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
+                swf_SetU16(tag, deletedepth);
+                deletedepth=-1;
+            }
+           rtag = rtag->next;
+            continue;
        }
 
        if(swf_isDefiningTag(rtag) && (flags&FLAGS_WRITEDEFINES))
@@ -737,7 +746,7 @@ TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefi
            {
                int id = get_free_id(masterbitmap);
                int depth = 65535;
-               deletedepth = 65536;
+               deletedepth = 65535;
                if(config.clip) {
                    msg("<fatal> Can't combine --clip and --frame");
                }
@@ -779,11 +788,6 @@ TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefi
                tag = swf_InsertTag(tag, rtag->id);
                write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley, 1);
                
-               if(rtag->id == ST_SHOWFRAME && deletedepth) {
-                   tag = swf_InsertTag(tag, ST_REMOVEOBJECT2);
-                   swf_SetU16(tag, deletedepth);
-                   deletedepth = -1;
-               }
            }
        }
        rtag = rtag->next;
@@ -1121,6 +1125,11 @@ int main(int argn, char *argv[])
        msg("<error> Can't combine --cat and --merge");
        exit(1);
     }
+    
+    if(config.stack && config.cat) {
+       msg("<error> Can't combine --cat and --stack");
+       exit(1);
+    }
 
     if(config.stack) {
        if(config.overlay) {
@@ -1148,6 +1157,7 @@ int main(int argn, char *argv[])
            msg("<fatal> Failed to read from %s\n", master_filename);
            exit(1);
        }
+       swf_RemoveJPEGTables(&master);
        msg("<debug> Read %d bytes from masterfile\n", ret);
        close(fi);
     }
@@ -1215,6 +1225,7 @@ int main(int argn, char *argv[])
                }
                msg("<debug> Read %d bytes from slavefile\n", ret);
                close(fi);
+               swf_RemoveJPEGTables(&slave);
            }
            else
            {
@@ -1228,6 +1239,12 @@ int main(int argn, char *argv[])
            combine(&master, slave_name[t], &slave, &newswf);
            master = newswf;
        }
+       if(config.dummy && !config.hassizex && !config.hassizey && !config.mastermovex && !config.mastermovey) {
+           newswf.movieSize.xmin = newswf.movieSize.xmin*config.masterscalex;
+           newswf.movieSize.ymin = newswf.movieSize.ymin*config.masterscaley;
+           newswf.movieSize.xmax = newswf.movieSize.xmax*config.masterscalex;
+           newswf.movieSize.ymax = newswf.movieSize.ymax*config.masterscaley;
+       }
     }
 
     fi = open(outputname, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);