+void printhandlerflags(U32 handlerflags)
+{
+ if(handlerflags&1) printf("[on load]");
+ if(handlerflags&2) printf("[enter frame]");
+ if(handlerflags&4) printf("[unload]");
+ if(handlerflags&8) printf("[mouse move]");
+ if(handlerflags&16) printf("[mouse down]");
+ if(handlerflags&32) printf("[mouse up]");
+ if(handlerflags&64) printf("[key down]");
+ if(handlerflags&128) printf("[key up]");
+
+ if(handlerflags&256) printf("[data]");
+ if(handlerflags&512) printf("[initialize]");
+ if(handlerflags&1024) printf("[mouse press]");
+ if(handlerflags&2048) printf("[mouse release]");
+ if(handlerflags&4096) printf("[mouse release outside]");
+ if(handlerflags&8192) printf("[mouse rollover]");
+ if(handlerflags&16384) printf("[mouse rollout]");
+ if(handlerflags&32768) printf("[mouse drag over]");
+
+ if(handlerflags&0x10000) printf("[mouse drag out]");
+ if(handlerflags&0x20000) printf("[key press]");
+ if(handlerflags&0x40000) printf("[construct even]");
+ if(handlerflags&0xfff80000) printf("[???]");
+}
+void handleVideoStream(TAG*tag, char*prefix)
+{
+ U16 id = swf_GetU16(tag);
+ U16 frames = swf_GetU16(tag);
+ U16 width = swf_GetU16(tag);
+ U16 height = swf_GetU16(tag);
+ U8 flags = swf_GetU8(tag); //5-2(videopacket 01=off 10=on)-1(smoothing 1=on)
+ U8 codec = swf_GetU8(tag);
+ printf(" (%d frames, %dx%d", frames, width, height);
+ if(flags&1)
+ printf(" smoothed");
+ if(codec == 2)
+ printf(" sorenson h.263)");
+ else
+ printf(" codec 0x%02x)", codec);
+}
+void handleVideoFrame(TAG*tag, char*prefix)
+{
+ U32 code, version, reference, sizeflags;
+ U32 width=0, height=0;
+ U8 type;
+ U16 id = swf_GetU16(tag);
+ U16 frame = swf_GetU16(tag);
+ U8 deblock,flags, tmp, bit;
+ U32 quantizer;
+ char*types[] = {"I-frame", "P-frame", "disposable P-frame", "<reserved>"};
+ printf(" (frame %d) ", frame);
+
+ /* video packet follows */
+ code = swf_GetBits(tag, 17);
+ version = swf_GetBits(tag, 5);
+ reference = swf_GetBits(tag, 8);
+
+ sizeflags = swf_GetBits(tag, 3);
+ switch(sizeflags)
+ {
+ case 0: width = swf_GetBits(tag, 8); height = swf_GetBits(tag, 8); break;
+ case 1: width = swf_GetBits(tag, 16); height = swf_GetBits(tag, 16); break;
+ case 2: width = 352; height = 288; break;
+ case 3: width = 176; height = 144; break;
+ case 4: width = 128; height = 96; break;
+ case 5: width = 320; height = 240; break;
+ case 6: width = 160; height = 120; break;
+ case 7: width = -1; height = -1;/*reserved*/ break;
+ }
+ printf("%dx%d ", width, height);
+ type = swf_GetBits(tag, 2);
+ printf("%s", types[type]);
+
+ deblock = swf_GetBits(tag, 1);
+ if(deblock)
+ printf(" deblock ", deblock);
+ quantizer = swf_GetBits(tag, 5);
+ printf(" quant: %d ", quantizer);
+}
+
+void dumpFilter(FILTER*filter)
+{
+ if(filter->type == FILTERTYPE_BLUR) {
+ FILTER_BLUR*f = (FILTER_BLUR*)filter;
+ printf("blurx: %f blury: %f\n", f->blurx, f->blury);
+ printf("passes: %d\n", f->passes);
+ } if(filter->type == FILTERTYPE_GLOW) {
+ FILTER_GLOW*f = (FILTER_GLOW*)filter;
+ printf("color %02x%02x%02x%02x\n", f->rgba.r,f->rgba.g,f->rgba.b,f->rgba.a);
+ printf("blurx: %f blury: %f strength: %f\n", f->blurx, f->blury, f->strength);
+ printf("passes: %d\n", f->passes);
+ printf("flags: %s%s%s\n",
+ f->knockout?"knockout ":"",
+ f->composite?"composite ":"",
+ f->innerglow?"innerglow":"");
+ } if(filter->type == FILTERTYPE_DROPSHADOW) {
+ FILTER_DROPSHADOW*f = (FILTER_DROPSHADOW*)filter;
+ printf("blurx: %f blury: %f\n", f->blurx, f->blury);
+ printf("passes: %d\n", f->passes);
+ printf("angle: %f distance: %f\n", f->angle, f->distance);
+ printf("strength: %f passes: %d\n", f->strength, f->passes);
+ printf("flags: %s%s%s\n",
+ f->knockout?"knockout ":"",
+ f->composite?"composite ":"",
+ f->innershadow?"innershadow ":"");
+ } if(filter->type == FILTERTYPE_BEVEL) {
+ FILTER_BEVEL*f = (FILTER_BEVEL*)filter;
+ printf("blurx: %f blury: %f\n", f->blurx, f->blury);
+ printf("passes: %d\n", f->passes);
+ printf("angle: %f distance: %f\n", f->angle, f->distance);
+ printf("strength: %f passes: %d\n", f->strength, f->passes);
+ printf("flags: %s%s%s%s\n",
+ f->ontop?"ontop":"",
+ f->knockout?"knockout ":"",
+ f->composite?"composite ":"",
+ f->innershadow?"innershadow ":"");
+ } if(filter->type == FILTERTYPE_GRADIENTGLOW) {
+ FILTER_GRADIENTGLOW*f = (FILTER_GRADIENTGLOW*)filter;
+ swf_DumpGradient(stdout, f->gradient);
+ printf("blurx: %f blury: %f\n", f->blurx, f->blury);
+ printf("angle: %f distance: %f\n", f->angle, f->distance);
+ printf("strength: %f passes: %d\n", f->strength, f->passes);
+ printf("flags: %s%s%s%s\n",
+ f->knockout?"knockout ":"",
+ f->ontop?"ontop ":"",
+ f->composite?"composite ":"",
+ f->innershadow?"innershadow ":"");
+ }
+ rfx_free(filter);
+}
+
+void handlePlaceObject23(TAG*tag, char*prefix)
+{
+ U8 flags,flags2=0;
+ MATRIX m;
+ CXFORM cx;
+ char pstr[3][256];
+ int ppos[3] = {0,0,0};
+ swf_SetTagPos(tag, 0);
+ flags = swf_GetU8(tag);
+ if(tag->id == ST_PLACEOBJECT3)
+ flags2 = swf_GetU8(tag);
+ swf_GetU16(tag); //depth
+
+ //flags&1: move
+ if(flags&2) swf_GetU16(tag); //id
+ if(flags&4) {
+ swf_GetMatrix(tag,&m);
+ if(placements) {
+ ppos[0] += sprintf(pstr[0], "| Matrix ");
+ ppos[1] += sprintf(pstr[1], "| %5.3f %5.3f %6.2f ", m.sx/65536.0, m.r1/65536.0, m.tx/20.0);
+ ppos[2] += sprintf(pstr[2], "| %5.3f %5.3f %6.2f ", m.r0/65536.0, m.sy/65536.0, m.ty/20.0);
+ }
+ }
+ if(flags&8) {
+ swf_GetCXForm(tag, &cx, 1);
+ if(placements) {
+ ppos[0] += sprintf(pstr[0]+ppos[0], "| CXForm r g b a ");
+ ppos[1] += sprintf(pstr[1]+ppos[1], "| mul %4.1f %4.1f %4.1f %4.1f ", cx.r0/256.0, cx.g0/256.0, cx.b0/256.0, cx.a0/256.0);
+ ppos[2] += sprintf(pstr[2]+ppos[2], "| add %4d %4d %4d %4d ", cx.r1, cx.g1, cx.b1, cx.a1);
+ }
+ }
+ if(flags&16) {
+ U16 ratio = swf_GetU16(tag); //ratio
+ if(placements) {
+ ppos[0] += sprintf(pstr[0]+ppos[0], "| Ratio ");
+ ppos[1] += sprintf(pstr[1]+ppos[1], "| %-5d ", ratio);
+ ppos[2] += sprintf(pstr[2]+ppos[2], "| ");
+ }
+ }
+ if(flags&64) {
+ U16 clip = swf_GetU16(tag); //clip
+ if(placements) {
+ ppos[0] += sprintf(pstr[0]+ppos[0], "| Clip ");
+ ppos[1] += sprintf(pstr[1]+ppos[1], "| %-4d ", clip);
+ ppos[2] += sprintf(pstr[2]+ppos[2], "| ");
+ }
+ }
+ if(flags&32) { while(swf_GetU8(tag)); }
+
+ if(flags2&1) { // filter list
+ U8 num = swf_GetU8(tag);
+ if(placements)
+ printf("\n%d filters\n", num);
+ char*filtername[] = {"dropshadow","blur","glow","bevel","gradientglow","convolution","colormatrix","gradientbevel"};
+ int t;
+ for(t=0;t<num;t++) {
+ FILTER*filter = swf_GetFilter(tag);
+ if(!filter) {
+ printf("\n");
+ return;
+ }
+ if(placements) {
+ printf("filter %d: %02x (%s)\n", t, filter->type, (filter->type<sizeof(filtername)/sizeof(filtername[0]))?filtername[filter->type]:"?");
+ dumpFilter(filter);
+ }
+ }
+ }
+ if(flags2&2) { // blend mode
+ U8 blendmode = swf_GetU8(tag);
+ if(placements) {
+ int t;
+ char name[80];
+ sprintf(name, "%-5d", blendmode);
+ for(t=0;blendModeNames[t];t++) {
+ if(blendmode==t) {
+ sprintf(name, "%-5s", blendModeNames[t]);
+ break;
+ }
+ }
+ ppos[0] += sprintf(pstr[0]+ppos[0], "| Blend ");
+ ppos[1] += sprintf(pstr[1]+ppos[1], "| %s ", name);
+ ppos[2] += sprintf(pstr[2]+ppos[2], "| ");
+ }
+ }
+
+ if(placements && ppos[0]) {
+ printf("\n");
+ printf("%s %s\n", prefix, pstr[0]);
+ printf("%s %s\n", prefix, pstr[1]);
+ printf("%s %s", prefix, pstr[2]);
+ }
+ if(flags&128) {
+ if (action) {
+ U16 reserved;
+ U32 globalflags;
+ U32 handlerflags;
+ char is32 = 0;
+ printf("\n");
+ reserved = swf_GetU16(tag); // must be 0
+ globalflags = swf_GetU16(tag); //TODO: 32 if version>=6
+ if(reserved) {
+ printf("Unknown parameter field not zero: %04x\n", reserved);
+ return;
+ }
+ printf("global flags: %04x\n", globalflags);
+
+ handlerflags = swf_GetU16(tag); //TODO: 32 if version>=6
+ if(!handlerflags) {
+ handlerflags = swf_GetU32(tag);
+ is32 = 1;
+ }
+ while(handlerflags) {
+ int length;
+ int t;
+ ActionTAG*a;
+
+ globalflags &= ~handlerflags;
+ printf("%s flags %08x ",prefix, handlerflags);
+ printhandlerflags(handlerflags);
+ length = swf_GetU32(tag);
+ printf(", %d bytes actioncode\n",length);
+ a = swf_ActionGet(tag);
+ swf_DumpActions(a,prefix);
+ swf_ActionFree(a);
+
+ handlerflags = is32?swf_GetU32(tag):swf_GetU16(tag); //TODO: 32 if version>=6
+ }
+ if(globalflags) // should go to sterr.
+ printf("ERROR: unsatisfied handlerflags: %02x\n", globalflags);
+ } else {
+ printf(" has action code\n");
+ }
+ } else printf("\n");
+}
+
+void handlePlaceObject(TAG*tag, char*prefix)
+{
+ TAG*tag2 = swf_InsertTag(0, ST_PLACEOBJECT2);
+ U16 id, depth;
+ MATRIX matrix;
+ CXFORM cxform;
+
+ swf_SetTagPos(tag, 0);
+ id = swf_GetU16(tag);
+ depth = swf_GetU16(tag);
+ swf_GetMatrix(tag, &matrix);
+ swf_GetCXForm(tag, &cxform, 0);
+
+ swf_SetU8(tag2, 14 /* char, matrix, cxform */);
+ swf_SetU16(tag2, depth);
+ swf_SetU16(tag2, id);
+ swf_SetMatrix(tag2, &matrix);
+ swf_SetCXForm(tag2, &cxform, 1);
+
+ handlePlaceObject23(tag2, prefix);
+}
+char stylebuf[256];
+char* fillstyle2str(FILLSTYLE*style)
+{
+ switch(style->type) {
+ case 0x00:
+ sprintf(stylebuf, "SOLID %02x%02x%02x%02x", style->color.r, style->color.g, style->color.b, style->color.a);
+ break;
+ case 0x10: case 0x11: case 0x12: case 0x13:
+ sprintf(stylebuf, "GRADIENT (%d steps)", style->gradient.num);
+ break;
+ case 0x40: case 0x42:
+ /* TODO: display information about that bitmap */
+ sprintf(stylebuf, "BITMAPt%s %d", (style->type&2)?"n":"", style->id_bitmap);
+ /* TODO: show matrix */
+ //swf_DumpMatrix(stdout, &style->m);
+ break;
+ case 0x41: case 0x43:
+ /* TODO: display information about that bitmap */
+ sprintf(stylebuf, "BITMAPc%s %d", (style->type&2)?"n":"", style->id_bitmap);
+ /* TODO: show matrix */
+ //swf_DumpMatrix(stdout, &style->m);
+ break;
+ default:
+ sprintf(stylebuf, "UNKNOWN[%02x]",style->type);
+ }
+ return stylebuf;
+}
+char* linestyle2str(LINESTYLE*style)
+{
+ sprintf(stylebuf, "%.2f %02x%02x%02x%02x", style->width/20.0, style->color.r, style->color.g, style->color.b, style->color.a);
+ return stylebuf;
+}
+
+void handleShape(TAG*tag, char*prefix)
+{
+ SHAPE2 shape;
+ SHAPELINE*line;
+ int t,max;
+
+ tag->pos = 0;
+ tag->readBit = 0;
+ swf_ParseDefineShape(tag, &shape);
+
+ max = shape.numlinestyles > shape.numfillstyles?shape.numlinestyles:shape.numfillstyles;
+
+ if(max) printf("%s | fillstyles(%02d) linestyles(%02d)\n",
+ prefix,
+ shape.numfillstyles,
+ shape.numlinestyles
+ );
+ else printf("%s | (Neither line nor fill styles)\n", prefix);
+
+ for(t=0;t<max;t++) {
+ printf("%s", prefix);
+ if(t < shape.numfillstyles) {
+ printf(" | %-2d) %-18.18s", t+1, fillstyle2str(&shape.fillstyles[t]));
+ } else {
+ printf(" ");
+ }
+ if(t < shape.numlinestyles) {
+ printf("%-2d) %s", t+1, linestyle2str(&shape.linestyles[t]));
+ }
+ printf("\n");
+ //if(shape.fillstyles[t].type&0x40) {
+ // MATRIX m = shape.fillstyles[t].m;
+ // swf_DumpMatrix(stdout, &m);
+ //}
+ }
+
+ printf("%s |\n", prefix);
+
+ line = shape.lines;
+ while(line) {
+ printf("%s | fill: %02d/%02d line:%02d - ",
+ prefix,
+ line->fillstyle0,
+ line->fillstyle1,
+ line->linestyle);
+ if(line->type == moveTo) {
+ printf("moveTo %.2f %.2f\n", line->x/20.0, line->y/20.0);
+ } else if(line->type == lineTo) {
+ printf("lineTo %.2f %.2f\n", line->x/20.0, line->y/20.0);
+ } else if(line->type == splineTo) {
+ printf("splineTo (%.2f %.2f) %.2f %.2f\n",
+ line->sx/20.0, line->sy/20.0,
+ line->x/20.0, line->y/20.0
+ );
+ }
+ line = line->next;
+ }
+ printf("%s |\n", prefix);
+}