added swf_DumpSWF function.
[swftools.git] / lib / modules / swfdump.c
1 /* swfdump.c
2
3    Dump / debug functions
4    
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2001 Rainer Böhme <rfxswf@reflex-studio.de>
9  
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
23
24 void swf_DumpHeader(FILE * f,SWF * swf)
25 { if (!f) f = stderr;
26   fprintf(f,"File size\t%u\n",swf->fileSize);
27   fprintf(f,"Movie width\t%u\n",(swf->movieSize.xmax - swf->movieSize.xmin)/20);
28   fprintf(f,"Movie height\t%u\n",(swf->movieSize.ymax - swf->movieSize.ymin)/20);
29   fprintf(f,"Frame rate\t%u.%u\n",swf->frameRate>>8,swf->frameRate&0xff);
30   fprintf(f,"Frame count\t%u\n",swf->frameCount);
31 }
32
33 void swf_DumpMatrix(FILE * f,MATRIX * m)
34 { if (!f) f = stderr;
35   fprintf(f,"[%08x][%08x]\n",m->sx,m->r1);
36   fprintf(f,"[%08x][%08x]\n",m->r0,m->sy);
37   fprintf(f," %08x, %08x\n",m->tx,m->ty);
38 }
39
40 void swf_DumpTag(FILE * f,TAG * t)
41 { int i;
42   if (!f) f = stderr;
43   for (i=0;i<t->len;i++)
44   { if (!(i&15)) fprintf(f,"\n");
45     fprintf(f,"%02x ",t->data[i]);
46   }
47   fprintf(f,"\n");
48 }
49
50 void swf_DumpSWF(FILE * f, SWF*swf)
51 {
52     TAG* tag = swf->firstTag;
53     fprintf(f, "vvvvvvvvvvvvvvvvvvvvv\n");
54     while(tag) {
55         printf("%8d %s\n", tag->len, swf_TagGetName(tag));
56         tag = tag->next;
57     }
58     fprintf(f, "^^^^^^^^^^^^^^^^^^^^^\n");
59 }
60
61 void swf_DumpFont(SWFFONT * font)
62 {
63     printf("ID: %d\n", font->id);
64     printf("Version: %d\n", font->version);
65     printf("name: %s\n", font->name);
66     printf("characters: %d\n", font->numchars);
67     printf("biggest mapped ascii value: %d\n", font->maxascii);
68     printf("layout: %s\n", font->layout?"yes":"no");
69     if(font->layout)
70     {
71         printf(" ascent:%d\n", font->layout->ascent);
72         printf(" descent:%d\n", font->layout->descent);
73         printf(" leading:%d\n", font->layout->leading);
74         printf(" bounds: (not shown)\n");
75         printf(" kerning records:%d\n", font->layout->kerningcount);
76         printf(" kerning records: (not shown)\n");
77     }
78     printf("style: %d\n", font->style);
79     printf("encoding: %d\n", font->encoding);
80     printf("language: %d\n", font->language);
81 }
82
83 char* swf_TagGetName(TAG*tag)
84 {
85     switch(tag->id)
86     {
87         case ST_END:
88             return "END";
89         case ST_SHOWFRAME:
90             return "SHOWFRAME";
91         case ST_DEFINESHAPE:
92             return "DEFINESHAPE";
93         case ST_FREECHARACTER:
94             return "FREECHARACTER";
95         case ST_PLACEOBJECT:
96             return "PLACEOBJECT";
97         case ST_REMOVEOBJECT:
98             return "REMOVEOBJECT";
99         case ST_DEFINEBITS:
100             return "DEFINEBITS";
101         case ST_DEFINEBUTTON:
102             return "DEFINEBUTTON";
103         case ST_JPEGTABLES:
104             return "JPEGTABLES";
105         case ST_SETBACKGROUNDCOLOR:
106             return "SETBACKGROUNDCOLOR";
107         case ST_DEFINEFONT:
108             return "DEFINEFONT";
109         case ST_DEFINETEXT:
110             return "DEFINETEXT";
111         case ST_DEFINEEDITTEXT:
112             return "DEFINEEDITTEXT";
113         case ST_DOACTION:
114             return "DOACTION";
115         case ST_DEFINEFONTINFO:
116             return "DEFINEFONTINFO";
117         case ST_DEFINESOUND:
118             return "DEFINESOUND";
119         case ST_STARTSOUND:
120             return "STARTSOUND";
121         case ST_DEFINEBUTTONSOUND:
122             return "DEFINEBUTTONSOUND";
123         case ST_SOUNDSTREAMHEAD:
124             return "SOUNDSTREAMHEAD";
125         case ST_SOUNDSTREAMBLOCK:
126             return "SOUNDSTREAMBLOCK";
127         case ST_DEFINEBITSLOSSLESS:
128             return "DEFINEBITSLOSSLESS";
129         case ST_DEFINEBITSJPEG2:
130             return "DEFINEBITSJPEG2";
131         case ST_DEFINESHAPE2:
132             return "DEFINESHAPE2";
133         case ST_DEFINEBUTTONCXFORM:
134             return "DEFINEBUTTONCXFORM";
135         case ST_PROTECT:
136             return "PROTECT";
137         case ST_PLACEOBJECT2:
138             return "PLACEOBJECT2";
139         case ST_REMOVEOBJECT2:
140             return "REMOVEOBJECT2";
141         case ST_DEFINESHAPE3:
142             return "DEFINESHAPE3";
143         case ST_DEFINETEXT2:
144             return "DEFINETEXT2";
145         case ST_DEFINEBUTTON2:
146             return "DEFINEBUTTON2";
147         case ST_DEFINEBITSJPEG3:
148             return "DEFINEBITSJPEG3";
149         case ST_DEFINEBITSLOSSLESS2:
150             return "DEFINEBITSLOSSLESS2";
151         case ST_DEFINESPRITE:
152             return "DEFINESPRITE";
153         case ST_NAMECHARACTER:
154             return "NAMECHARACTER";
155         case ST_SERIALNUMBER:
156             return "SERIALNUMBER";
157         case ST_GENERATORTEXT:
158             return "GENERATORTEXT";
159         case ST_FRAMELABEL:
160             return "FRAMELABEL";
161         case ST_SOUNDSTREAMHEAD2:
162             return "SOUNDSTREAMHEAD2";
163         case ST_DEFINEMORPHSHAPE:
164             return "DEFINEMORPHSHAPE";
165         case ST_DEFINEFONT2:
166             return "DEFINEFONT2";
167         case ST_TEMPLATECOMMAND:
168             return "TEMPLATECOMMAND";
169         case ST_GENERATOR3:
170             return "GENERATOR3";
171         case ST_EXTERNALFONT:
172             return "EXTERNALFONT";
173         case ST_EXPORTASSETS:
174             return "EXPORTASSETS";
175         case ST_IMPORTASSETS:
176             return "IMPORTASSETS";
177         case ST_ENABLEDEBUGGER:
178             return "ENABLEDEBUGGER";
179         case ST_REFLEX:
180             return "REFLEX";
181         case ST_DOINITACTION:
182             return "DOINITACTION";
183         case ST_DEFINEMOVIE:
184             return "DEFINEMOVIE";
185         case ST_DEFINEVIDEOSTREAM:
186             return "DEFINEVIDEOSTREAM";
187         case ST_VIDEOFRAME:
188             return "VIDEOFRAME";
189         case ST_DEFINEFONTINFO2:
190             return "DEFINEFONTINFO2";
191         case ST_FREEALL:
192             return "FREEALL";
193         case ST_MX4:
194             return "MX4";
195     }
196     return 0;
197 }