added swfbbox.
[swftools.git] / src / swfcombine.c
index 4089f5b..e76b5c6 100644 (file)
@@ -10,7 +10,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <zlib.h>
 #include "../lib/rfxswf.h"
 #include "../lib/args.h"
 #include "../lib/log.h"
@@ -279,7 +278,7 @@ static void makestackmaster(SWF*swf)
     {
        SWF head;
        int ret;
-       int fi=open(slave_filename[t],O_RDONLY);
+       int fi=open(slave_filename[t],O_RDONLY|O_BINARY);
        TAG*tag;
        if(fi<0 || swf_ReadSWF(fi, &head)<0) {
            logf("<fatal> Couldn't open/read %s.", slave_filename[t]);
@@ -487,17 +486,21 @@ void changedepth(TAG*tag, int add)
        PUT16(&tag->data[0],GET16(&tag->data[0])+add);
 }
 
-void matrix_adjust(MATRIX*m, int movex, int movey, float scalex, float scaley)
+void matrix_adjust(MATRIX*m, int movex, int movey, float scalex, float scaley, int scalepos)
 {
     m->sx = (int)(m->sx*scalex);
     m->sy = (int)(m->sy*scaley);
-    m->r0 = (int)(m->r0*scalex);
-    m->r1 = (int)(m->r1*scaley);
+    m->r1 = (int)(m->r1*scalex);
+    m->r0 = (int)(m->r0*scaley);
+    if(scalepos) {
+       m->tx *= scalex;
+       m->ty *= scaley;
+    }
     m->tx += movex;
     m->ty += movey;
 }
 
-void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, float scaley)
+void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, float scaley, int scalepos)
 {
     if(movex || movey || scalex != 1 || scaley != 1)
     {
@@ -523,7 +526,7 @@ void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, fl
                } else {
                    swf_GetMatrix(0, &m);
                }
-               matrix_adjust(&m, movex, movey, scalex, scaley);
+               matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
                swf_SetMatrix(output, &m);
 
                //swf_ResetReadBits(tag);
@@ -536,7 +539,7 @@ void write_changepos(TAG*output, TAG*tag, int movex, int movey, float scalex, fl
                swf_SetU16(output, swf_GetU16(tag)); //depth
                
                swf_GetMatrix(tag, &m);
-               matrix_adjust(&m, movex, movey, scalex, scaley);
+               matrix_adjust(&m, movex, movey, scalex, scaley, scalepos);
                swf_SetMatrix(output, &m);
                
                //swf_ResetReadBits(tag);
@@ -590,7 +593,7 @@ TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
            logf("<debug> [sprite main] write tag %02x (%d bytes in body)", 
                    rtag->id, rtag->len);
            tag = swf_InsertTag(tag, rtag->id);
-           write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley);
+           write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley, 0);
        
            changedepth(tag, +2);
 
@@ -725,7 +728,7 @@ TAG* write_master(TAG*tag, SWF*master, SWF*slave, int spriteid, int replaceddefi
                logf("<debug> [master] write tag %02x (%d bytes in body)", 
                        rtag->id, rtag->len);
                tag = swf_InsertTag(tag, rtag->id);
-               write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley);
+               write_changepos(tag, rtag, config.mastermovex, config.mastermovey, config.masterscalex, config.masterscaley, 1);
            }
        }
        rtag = rtag->next;
@@ -1071,7 +1074,7 @@ int main(int argn, char *argv[])
     else {
        int ret;
        logf("<verbose> master entity %s (named \"%s\")\n", master_filename, master_name);
-       fi = open(master_filename, O_RDONLY);
+       fi = open(master_filename, O_RDONLY|O_BINARY);
        if(fi<0) {
            logf("<fatal> Failed to open %s\n", master_filename);
            exit(1);
@@ -1136,7 +1139,7 @@ int main(int argn, char *argv[])
            if(!config.dummy)
            {
                int ret;
-               fi = open(slave_filename[t], O_RDONLY);
+               fi = open(slave_filename[t], O_RDONLY|O_BINARY);
                if(!fi) {
                    logf("<fatal> Failed to open %s\n", slave_filename[t]);
                    exit(1);
@@ -1163,7 +1166,7 @@ int main(int argn, char *argv[])
        }
     }
 
-    fi = open(outputname, O_RDWR|O_TRUNC|O_CREAT, 0777);
+    fi = open(outputname, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);
 
     if(config.zlib)
        swf_WriteSWC(fi, &newswf);