always set the version to 6 if the file is zlib-compressed.
[swftools.git] / src / swfcombine.c
index f6257fe..78af839 100644 (file)
@@ -288,7 +288,7 @@ static void makestackmaster(SWF*swf)
     TAG*tag;
     int t;
     SRECT box;
-    int fileversion = 1;
+    int fileversion = config.zlib?6:3;
     int frameRate = 256;
     RGBA rgb;
     rgb.r=rgb.b=rgb.g=0;
@@ -497,7 +497,6 @@ TAG* write_sprite_defines(TAG*tag, SWF*sprite)
 
 void changedepth(TAG*tag, int add)
 {
-    /* fucking byteorders */
     if(tag->id == ST_PLACEOBJECT)
        PUT16(&tag->data[2],GET16(&tag->data[2])+add);
     if(tag->id == ST_PLACEOBJECT2)
@@ -506,6 +505,23 @@ void changedepth(TAG*tag, int add)
        PUT16(&tag->data[2],GET16(&tag->data[2])+add);
     if(tag->id == ST_REMOVEOBJECT2)
        PUT16(&tag->data[0],GET16(&tag->data[0])+add);
+    if(tag->id == ST_PLACEOBJECT2) {
+       SWFPLACEOBJECT obj;
+       U8 flags;
+       swf_SetTagPos(tag, 0);
+       flags = swf_GetU8(tag);
+       if(flags&2) swf_GetU16(tag); //id
+       if(flags&4) swf_GetMatrix(tag, 0);
+       if(flags&8) swf_GetCXForm(tag, 0,1);
+       if(flags&16) swf_GetU16(tag); //ratio
+       if(flags&64) {
+           swf_ResetReadBits(tag);
+           printf("%d->%d\n", GET16(&tag->data[tag->pos]),
+                              GET16(&tag->data[tag->pos])+add);
+           PUT16(&tag->data[tag->pos],GET16(&tag->data[tag->pos])+add);
+       }
+       msg("<warning> Depth relocation not fully working yet with clipdepths", tag->id);
+    }
 }
 
 void matrix_adjust(MATRIX*m, int movex, int movey, float scalex, float scaley, int scalepos)
@@ -618,8 +634,9 @@ TAG* write_sprite(TAG*tag, SWF*sprite, int spriteid, int replaceddefine)
                    rtag->id, rtag->len);
            tag = swf_InsertTag(tag, rtag->id);
            write_changepos(tag, rtag, config.movex, config.movey, config.scalex, config.scaley, 0);
-       
-           changedepth(tag, +2);
+
+           if(config.clip || (config.overlay && !config.isframe))
+               changedepth(tag, +2);
 
            if(tag->id == ST_SHOWFRAME)
            {
@@ -957,7 +974,8 @@ void normalcombine(SWF*master, char*slave_name, SWF*slave, SWF*newswf)
     }
 
     swf_Relocate (slave, masterbitmap);
-    swf_RelocateDepth (slave, depthbitmap);
+    if(config.merge)
+       swf_RelocateDepth (slave, depthbitmap);
     jpeg_assert(slave, master);
     
     if (config.overlay)
@@ -1200,9 +1218,11 @@ int main(int argn, char *argv[])
 
     fi = open(outputname, O_BINARY|O_RDWR|O_TRUNC|O_CREAT, 0777);
 
-    if(config.zlib)
+    if(config.zlib) {
+       if(newswf.fileVersion < 6)
+           newswf.fileVersion = 6;
        swf_WriteSWC(fi, &newswf);
-    else {
+    } else {
        newswf.compressed = 0;
        swf_WriteSWF(fi, &newswf);
     }