#include <math.h>
[swftools.git] / src / swfdump.c
index a6c0f78..9a06d26 100644 (file)
@@ -249,6 +249,46 @@ void handleText(TAG*tag)
   printf("\n");
   swf_FontExtract_DefineTextCallback(-1,0,tag,4, textcallback);
 }
+           
+void handleDefineSound(TAG*tag)
+{
+    U16 id = swf_GetU16(tag);
+    U8 flags = swf_GetU8(tag);
+    int compression = (flags>>4)&3;
+    int rate = (flags>>2)&3;
+    int bits = flags&2?16:8;
+    int stereo = flags&1;
+    printf(" (");
+    if(compression == 0) printf("Raw ");
+    else if(compression == 1) printf("ADPCM ");
+    else if(compression == 2) printf("MP3 ");
+    else printf("? ");
+    if(rate == 0) printf("5.5Khz ");
+    if(rate == 1) printf("11Khz ");
+    if(rate == 2) printf("22Khz ");
+    if(rate == 3) printf("44Khz ");
+    printf("%dBit ", bits);
+    if(stereo) printf("stereo");
+    else printf("mono");
+    printf(")");
+}
+
+void handleDefineBits(TAG*tag)
+{
+    U16 id;
+    U8 mode;
+    U16 width,height;
+    int bpp;
+    id = swf_GetU16(tag);
+    mode = swf_GetU8(tag);
+    width = swf_GetU16(tag);
+    height = swf_GetU16(tag);
+    printf(" image %dx%d",width,height);
+    if(mode == 3) printf(" (8 bpp)");
+    else if(mode == 4) printf(" (16 bpp)");
+    else if(mode == 5) printf(" (32 bpp)");
+    else printf(" (? bpp)");
+}
 
 void handleEditText(TAG*tag)
 {
@@ -315,7 +355,6 @@ void printhandlerflags(U16 handlerflags)
 void handlePlaceObject2(TAG*tag, char*prefix)
 {
     U8 flags = swf_GetU8(tag);
-    printf("flags: %02x", flags);
     swf_GetU16(tag); //depth
     //flags&1: move
     if(flags&2) swf_GetU16(tag); //id
@@ -377,6 +416,22 @@ void fontcallback2(U16 id,U8 * name)
   fontnum++;
 }
 
+void hexdumpTag(TAG*tag, char* prefix)
+{
+    int t;
+    printf("                %s-=> ",prefix);
+    for(t=0;t<tag->len;t++) {
+       printf("%02x ", tag->data[t]);
+       if((t && ((t&15)==15)) || (t==tag->len-1))
+       {
+           if(t==tag->len-1)
+               printf("\n");
+           else
+               printf("\n                %s-=> ",prefix);
+       }
+    }
+}
+
 void dumperror(const char* format, ...)
 {
     char buf[1024];
@@ -386,7 +441,8 @@ void dumperror(const char* format, ...)
     vsprintf(buf, format, arglist);
     va_end(arglist);
 
-    printf("==== Error: %s ====\n", buf);
+    if(!html && !xy)
+       printf("==== Error: %s ====\n", buf);
 }
 
 int main (int argc,char ** argv)
@@ -398,9 +454,9 @@ int main (int argc,char ** argv)
     int f;
     int xsize,ysize;
     char issprite = 0; // are we inside a sprite definition?
-    int spriteframe;
+    int spriteframe = 0;
     int mainframe=0;
-    char* spriteframelabel;
+    char* spriteframelabel = 0;
     char* framelabel = 0;
     char prefix[128];
     int filesize = 0;
@@ -463,20 +519,29 @@ int main (int argc,char ** argv)
     }
     if(html)
     {
+       char*fileversions[] = {"","1,0,0,0", "2,0,0,0","3,0,0,0","4,0,0,0",
+                              "5,0,0,0","6,0,23,0","7,0,0,0","8,0,0,0"};
+       if(swf.fileVersion>8) {
+           fprintf(stderr, "Fileversion>8\n");
+           exit(1);
+       }
        printf("<OBJECT CLASSID=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n"
               " WIDTH=\"%d\"\n"
+              //" BGCOLOR=#ffffffff\n"?
               " HEIGHT=\"%d\"\n"
-              " CODEBASE=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=%d,0,0,0\">\n"
+              //http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,23,0?
+              " CODEBASE=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=%s\">\n"
                "  <PARAM NAME=\"MOVIE\" VALUE=\"%s\">\n"
               "  <PARAM NAME=\"PLAY\" VALUE=\"true\">\n" 
               "  <PARAM NAME=\"LOOP\" VALUE=\"true\">\n"
               "  <PARAM NAME=\"QUALITY\" VALUE=\"high\">\n"
-              "  <EMBED SRC=\"%s\" WIDTH=\"%d\" HEIGHT=\"%d\"\n"
-              "   PLAY=\"true\" LOOP=\"true\" QUALITY=\"high\"\n"
+              "  <EMBED SRC=\"%s\" WIDTH=\"%d\" HEIGHT=\"%d\"\n" //bgcolor=#ffffff?
+              "   PLAY=\"true\" ALIGN=\"\" LOOP=\"true\" QUALITY=\"high\"\n"
               "   TYPE=\"application/x-shockwave-flash\"\n"
-              "   PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\">\n"
+              "   PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">\n"
                "  </EMBED>\n" 
-              "</OBJECT>\n", xsize, ysize, swf.fileVersion, filename, filename, xsize, ysize);
+              "</OBJECT>\n", xsize, ysize, fileversions[swf.fileVersion], 
+                             filename, filename, xsize, ysize);
        return 0;
     } 
     printf("[HEADER]        File version: %d\n", swf.fileVersion);
@@ -557,6 +622,9 @@ int main (int argc,char ** argv)
         else if(tag->id == ST_REMOVEOBJECT2) {
             printf(" removes object from depth %04d", swf_GetDepth(tag));
         }
+        else if(tag->id == ST_FREECHARACTER) {
+            printf(" frees object %04d", swf_GetPlaceID(tag));
+        }
        else if(tag->id == ST_STARTSOUND) {
            printf(" starts id %04d", swf_GetPlaceID(tag));
        }
@@ -598,7 +666,16 @@ int main (int argc,char ** argv)
            if(!issprite) {mainframe++; framelabel = 0;}
        }
 
-       if(tag->id == ST_DEFINEEDITTEXT) {
+       if(tag->id == ST_DEFINEBITSLOSSLESS ||
+          tag->id == ST_DEFINEBITSLOSSLESS2) {
+           handleDefineBits(tag);
+           printf("\n");
+       }
+       else if(tag->id == ST_DEFINESOUND) {
+           handleDefineSound(tag);
+           printf("\n");
+       }
+       else if(tag->id == ST_DEFINEEDITTEXT) {
            handleEditText(tag);
            printf("\n");
        }
@@ -659,7 +736,7 @@ int main (int argc,char ** argv)
                swf_GetUsedIDs(tag, used);
                printf("%s%suses IDs: ", indent, prefix);
                for(t=0;t<num;t++) {
-                   tag->pos = used[t];
+                   swf_SetTagPos(tag, used[t]);
                    printf("%d%s", swf_GetU16(tag), t<num-1?", ":"");
                }
                printf("\n");
@@ -667,18 +744,7 @@ int main (int argc,char ** argv)
        }
 
        if(tag->len && hex) {
-           int t;
-           printf("                %s-=> ",prefix);
-           for(t=0;t<tag->len;t++) {
-               printf("%02x ", tag->data[t]);
-               if((t && ((t&15)==15)) || (t==tag->len-1))
-               {
-                   if(t==tag->len-1)
-                       printf("\n");
-                   else
-                       printf("\n                %s-=> ",prefix);
-               }
-           }
+           hexdumpTag(tag, prefix);
        }
         tag = tag->next;
        fflush(stdout);