fixed mem leak
[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   fprintf(f,"[%08x][%08x] %5.2f %5.2f %5.2f\n",m->sx,m->r1, m->sx/65536.0,m->r1/65536.0, m->tx/20.0);
39   fprintf(f,"[%08x][%08x] %5.2f %5.2f %5.2f\n",m->r0,m->sy, m->r0/65536.0,m->sy/65536.0, m->ty/20.0 );
40   fprintf(f," %08x, %08x \n",m->tx,m->ty);
41 }
42
43 void swf_DumpGradient(FILE * f,GRADIENT * g)
44 { if (!f) f = stderr;
45     fprintf(f, "%d gradient steps\n", g->num);
46     int t;
47     for(t=0;t<g->num;t++) {
48         RGBA c = g->rgba[t];
49         fprintf(f, "%d) %02x%02x%02x%02x at %d\n", t, c.r,c.g,c.b,c.a, g->ratios[t]);
50     }
51 }
52
53 void swf_DumpTag(FILE * f,TAG * t)
54 { int i;
55   if (!f) f = stderr;
56   for (i=0;i<t->len;i++)
57   { if (!(i&15)) fprintf(f,"\n");
58     fprintf(f,"%02x ",t->data[i]);
59   }
60   fprintf(f,"\n");
61 }
62
63 void swf_DumpSWF(FILE * f, SWF*swf)
64 {
65     TAG* tag = swf->firstTag;
66     fprintf(f, "vvvvvvvvvvvvvvvvvvvvv\n");
67     while(tag) {
68         printf("%8d %s\n", tag->len, swf_TagGetName(tag));
69         tag = tag->next;
70     }
71     fprintf(f, "^^^^^^^^^^^^^^^^^^^^^\n");
72 }
73
74 void swf_DumpFont(SWFFONT * font)
75 {
76     printf("ID: %d\n", font->id);
77     printf("Version: %d\n", font->version);
78     printf("name: %s\n", font->name);
79     printf("characters: %d\n", font->numchars);
80     printf("biggest mapped ascii value: %d\n", font->maxascii);
81     printf("layout: %s\n", font->layout?"yes":"no");
82     if(font->layout)
83     {
84         printf(" ascent:%d\n", font->layout->ascent);
85         printf(" descent:%d\n", font->layout->descent);
86         printf(" leading:%d\n", font->layout->leading);
87         printf(" bounds: (not shown)\n");
88         printf(" kerning records:%d\n", font->layout->kerningcount);
89         printf(" kerning records: (not shown)\n");
90     }
91     printf("style: %d\n", font->style);
92     printf("encoding: %d\n", font->encoding);
93     printf("language: %d\n", font->language);
94 }
95
96 void swf_DumpShape(SHAPE2*shape2)
97 {
98     SHAPELINE*l = shape2->lines;
99     while(l) {
100         if(l->type == moveTo) {
101             //printf("fill %d/%d line %d\n", l->fillstyle0, l->fillstyle1, l->linestyle);
102             printf("moveTo %.2f,%.2f (fill0:%d fill1:%d line:%d)\n", l->x/20.0, l->y/20.0, l->fillstyle0, l->fillstyle1, l->linestyle);
103         }
104         if(l->type == lineTo) {
105             //printf("fill %d/%d line %d\n", l->fillstyle0,  l->fillstyle1, l->linestyle);
106             printf("lineTo %.2f,%.2f (fill0:%d fill1:%d line:%d)\n", l->x/20.0, l->y/20.0, l->fillstyle0, l->fillstyle1, l->linestyle);
107         }
108         if(l->type == splineTo) {
109             //printf("fill %d/%d line %d\n", l->fillstyle0, l->fillstyle1, l->linestyle);
110             printf("splineTo %.2f,%.2f %.2f,%.2f (fill0:%d fill1:%d line:%d)\n", l->sx/20.0, l->sy/20.0, l->x/20.0, l->y/20.0, l->fillstyle0, l->fillstyle1, l->linestyle);
111         }
112         l = l->next;
113     }
114 }
115
116 char* swf_TagGetName(TAG*tag)
117 {
118     switch(tag->id)
119     {
120         case ST_END:
121             return "END";
122         case ST_SHOWFRAME:
123             return "SHOWFRAME";
124         case ST_DEFINESHAPE:
125             return "DEFINESHAPE";
126         case ST_FREECHARACTER:
127             return "FREECHARACTER";
128         case ST_PLACEOBJECT:
129             return "PLACEOBJECT";
130         case ST_REMOVEOBJECT:
131             return "REMOVEOBJECT";
132         case ST_DEFINEBITS:
133             return "DEFINEBITS";
134         case ST_DEFINEBUTTON:
135             return "DEFINEBUTTON";
136         case ST_JPEGTABLES:
137             return "JPEGTABLES";
138         case ST_SETBACKGROUNDCOLOR:
139             return "SETBACKGROUNDCOLOR";
140         case ST_DEFINEFONT:
141             return "DEFINEFONT";
142         case ST_DEFINETEXT:
143             return "DEFINETEXT";
144         case ST_DEFINEEDITTEXT:
145             return "DEFINEEDITTEXT";
146         case ST_DOACTION:
147             return "DOACTION";
148         case ST_DOABC:
149             return "DOABC";
150         case ST_DEFINEFONTINFO:
151             return "DEFINEFONTINFO";
152         case ST_DEFINESOUND:
153             return "DEFINESOUND";
154         case ST_STARTSOUND:
155             return "STARTSOUND";
156         case ST_DEFINEBUTTONSOUND:
157             return "DEFINEBUTTONSOUND";
158         case ST_SOUNDSTREAMHEAD:
159             return "SOUNDSTREAMHEAD";
160         case ST_SOUNDSTREAMBLOCK:
161             return "SOUNDSTREAMBLOCK";
162         case ST_DEFINEBITSLOSSLESS:
163             return "DEFINEBITSLOSSLESS";
164         case ST_DEFINEBITSJPEG2:
165             return "DEFINEBITSJPEG2";
166         case ST_DEFINESHAPE2:
167             return "DEFINESHAPE2";
168         case ST_DEFINEBUTTONCXFORM:
169             return "DEFINEBUTTONCXFORM";
170         case ST_PROTECT:
171             return "PROTECT";
172         case ST_PLACEOBJECT2:
173             return "PLACEOBJECT2";
174         case ST_REMOVEOBJECT2:
175             return "REMOVEOBJECT2";
176         case ST_DEFINESHAPE3:
177             return "DEFINESHAPE3";
178         case ST_DEFINETEXT2:
179             return "DEFINETEXT2";
180         case ST_DEFINEBUTTON2:
181             return "DEFINEBUTTON2";
182         case ST_DEFINEBITSJPEG3:
183             return "DEFINEBITSJPEG3";
184         case ST_DEFINEBITSLOSSLESS2:
185             return "DEFINEBITSLOSSLESS2";
186         case ST_DEFINESPRITE:
187             return "DEFINESPRITE";
188         case ST_NAMECHARACTER:
189             return "NAMECHARACTER";
190         case ST_SERIALNUMBER:
191             return "SERIALNUMBER";
192         case ST_GENERATORTEXT:
193             return "GENERATORTEXT";
194         case ST_FRAMELABEL:
195             return "FRAMELABEL";
196         case ST_SOUNDSTREAMHEAD2:
197             return "SOUNDSTREAMHEAD2";
198         case ST_DEFINEMORPHSHAPE:
199             return "DEFINEMORPHSHAPE";
200         case ST_DEFINEMORPHSHAPE2:
201             return "DEFINEMORPHSHAPE2";
202         case ST_DEFINEFONT2:
203             return "DEFINEFONT2";
204         case ST_TEMPLATECOMMAND:
205             return "TEMPLATECOMMAND";
206         case ST_GENERATOR3:
207             return "GENERATOR3";
208         case ST_EXTERNALFONT:
209             return "EXTERNALFONT";
210         case ST_EXPORTASSETS:
211             return "EXPORTASSETS";
212         case ST_SYMBOLCLASS:
213             return "SYMBOLCLASS";
214         case ST_DEFINEBINARY:
215             return "DEFINEBINARY";
216         case ST_IMPORTASSETS:
217             return "IMPORTASSETS";
218         case ST_ENABLEDEBUGGER:
219             return "ENABLEDEBUGGER";
220         case ST_DOINITACTION:
221             return "DOINITACTION";
222         case ST_DEFINEMOVIE:
223             return "DEFINEMOVIE";
224         case ST_DEFINEVIDEOSTREAM:
225             return "DEFINEVIDEOSTREAM";
226         case ST_VIDEOFRAME:
227             return "VIDEOFRAME";
228         case ST_DEFINEFONTINFO2:
229             return "DEFINEFONTINFO2";
230         case ST_FILEATTRIBUTES:
231             return "FILEATTRIBUTES";
232         case ST_IMPORTASSETS2:
233             return "IMPORTASSETS2";
234         case ST_DEFINESCALINGGRID:
235             return "DEFINESCALINGGRID";
236         case ST_DEFINESHAPE4:
237             return "DEFINESHAPE4";
238         case ST_DEFINEFONT3:
239             return "DEFINEFONT3";
240         case ST_DEFINEFONTALIGNZONES:
241             return "DEFINEFONTALIGNZONES";
242         case ST_DEFINEFONTNAME:
243             return "DEFINEFONTNAME";
244         case ST_CSMTEXTSETTINGS:
245             return "CSMTEXTSETTINGS";
246         case ST_FREEALL:
247             return "FREEALL";
248         case ST_MX4:
249             return "MX4";
250         case ST_SCRIPTLIMITS:
251             return "SCRIPTLIMITS";
252         case ST_SETTABINDEX:
253             return "SETTABINDEX";
254         case ST_ENABLEDEBUGGER2:
255             return "ENABLEDEBUGGER2";
256         case ST_PLACEOBJECT3:
257             return "PLACEOBJECT3";
258         case ST_METADATA:
259             return "METADATA";
260         case ST_SCENEDESCRIPTION:
261             return "SCENEDESCRIPTION";
262         
263         case ST_REFLEX:
264             return "REFLEX";
265         case ST_GLYPHNAMES:
266             return "GLYPHNAMES";
267     }
268     return 0;
269 }