generate long tags for soundstreamblock and definejpeg tags, too
[swftools.git] / lib / rfxswf.c
1 /* vi: set sts=2 sw=2 :*/
2 /* rfxswf.c 
3
4    Library for creating and reading SWF files or parts of it.
5    There's a module directory which provides some extended functionality.
6    Most modules are included at the bottom of this file.
7
8    Part of the swftools package.
9
10    Copyright (c) 2000-2003 Rainer Böhme <rfxswf@reflex-studio.de>
11    Copyright (c) 2003 Matthias Kramm <kramm@quiss.org> 
12
13    This program is free software; you can redistribute it and/or modify
14    it under the terms of the GNU General Public License as published by
15    the Free Software Foundation; either version 2 of the License, or
16    (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21    GNU General Public License for more details.
22
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
26
27 #include "mem.h"
28 #include "rfxswf.h"
29
30 #ifdef HAVE_JPEGLIB
31 #define HAVE_BOOLEAN
32 #include <jpeglib.h>
33 #endif // HAVE_JPEGLIB
34
35 #ifdef HAVE_ZLIB
36 #include <zlib.h>
37 #endif // HAVE_ZLIB
38
39 #ifndef RFXSWF_DISABLESOUND
40 #ifdef HAVE_LAME
41 #include "lame/lame.h"
42 #endif
43 #endif
44
45 #ifdef HAVE_TIME_H
46 #include <time.h>
47 #endif
48
49 #include "./bitio.h"
50 #include "./MD5.h"
51
52 // internal constants
53
54 #define MALLOC_SIZE     128
55 #define INSERT_RFX_TAG
56
57 #define MEMSIZE(l) (((l/MALLOC_SIZE)+1)*MALLOC_SIZE)
58
59 // inline wrapper functions
60
61 TAG * swf_NextTag(TAG * t) { return t->next; }
62 TAG * swf_PrevTag(TAG * t) { return t->prev; }
63 U16   swf_GetTagID(TAG * t)    { return t->id; }
64 U32   swf_GetTagLen(TAG * t) { return t->len; }
65 U8*   swf_GetTagLenPtr(TAG * t) { return &(t->data[t->len]); }
66 U32   swf_GetTagPos(TAG * t)   { return t->pos; }
67
68 // for future purpose: avoid high level lib functions to change tagpos/bitpos
69
70 #define swf_SaveTagPos(tag)
71 #define swf_RestoreTagPos(tag)
72
73 void swf_SetTagPos(TAG * t,U32 pos)
74 { swf_ResetReadBits(t);
75   if (pos<=t->len) t->pos = pos;
76   else { 
77 #ifdef DEBUG_RFXSWF
78     fprintf(stderr,"SetTagPos(%d) out of bounds: TagID = %i\n",pos, t->id);
79 #endif
80   }
81 }
82
83 char* swf_GetString(TAG*t)
84 {
85     char* str = ((char*)(&(t)->data[(t)->pos]));
86     while(swf_GetU8(t));
87     return str;
88 }
89
90 U8 swf_GetU8(TAG * t)
91 { swf_ResetReadBits(t);
92   #ifdef DEBUG_RFXSWF
93     if (t->pos>=t->len) 
94     { fprintf(stderr,"GetU8() out of bounds: TagID = %i\n",t->id);
95       return 0;
96     }
97   #endif
98   return t->data[t->pos++];
99 }
100
101 U16 swf_GetU16(TAG * t)
102 { U16 res;
103   swf_ResetReadBits(t);
104   #ifdef DEBUG_RFXSWF
105     if (t->pos>(t->len-2)) 
106     { fprintf(stderr,"GetU16() out of bounds: TagID = %i\n",t->id);
107       return 0;
108     }
109   #endif
110   res = t->data[t->pos] | (t->data[t->pos+1]<<8);
111   t->pos+=2;
112   return res;
113 }
114
115 U32 swf_GetU32(TAG * t)
116 { U32 res;
117   swf_ResetReadBits(t);
118   #ifdef DEBUG_RFXSWF
119     if (t->pos>(t->len-4)) 
120     { fprintf(stderr,"GetU32() out of bounds: TagID = %i\n",t->id);
121       return 0;
122     }
123   #endif
124   res = t->data[t->pos]        | (t->data[t->pos+1]<<8) | 
125        (t->data[t->pos+2]<<16) | (t->data[t->pos+3]<<24);
126   t->pos+=4;
127   return res;
128 }
129
130 int swf_GetBlock(TAG * t,U8 * b,int l)
131 // returns number of bytes written (<=l)
132 // b = NULL -> skip data
133 { swf_ResetReadBits(t);
134   if ((t->len-t->pos)<l) l=t->len-t->pos;
135   if (b && l) memcpy(b,&t->data[t->pos],l);
136   t->pos+=l;
137   return l;
138 }
139
140 int swf_SetBlock(TAG * t,U8 * b,int l)
141 // Appends Block to the end of Tagdata, returns size
142 { U32 newlen = t->len + l;
143   swf_ResetWriteBits(t);
144   if (newlen>t->memsize)
145   { U32  newmem  = MEMSIZE(newlen);  
146     U8 * newdata = (U8*)(rfx_realloc(t->data,newmem));
147     t->memsize = newmem;
148     t->data    = newdata;
149   }
150   if (b) memcpy(&t->data[t->len],b,l);
151   else memset(&t->data[t->len],0x00,l);
152   t->len+=l;
153   return l;
154 }
155
156 int swf_SetU8(TAG * t,U8 v)
157 { swf_ResetWriteBits(t);
158   if ((t->len+1)>t->memsize) return (swf_SetBlock(t,&v,1)==1)?0:-1;
159   t->data[t->len++] = v;
160   return 0;
161 }
162
163 int swf_SetU16(TAG * t,U16 v)
164 { U8 a[2];
165   a[0] = v&0xff;
166   a[1] = v>>8;
167   
168   swf_ResetWriteBits(t);
169   if ((t->len+2)>t->memsize) return (swf_SetBlock(t,a,2)==2)?0:-1;
170   t->data[t->len++] = a[0];
171   t->data[t->len++] = a[1];
172   return 0;
173 }
174 void swf_SetS16(TAG * t,int v)
175 {
176     if(v>32767 || v<-32768) {
177         fprintf(stderr, "Warning: S16 overflow: %d\n", v);
178     }
179     swf_SetU16(t, (S16)v);
180 }
181
182 int swf_SetU32(TAG * t,U32 v)
183 { U8 a[4];
184   a[0] = v&0xff;        // to ensure correct handling of non-intel byteorder
185   a[1] = (v>>8)&0xff;
186   a[2] = (v>>16)&0xff;
187   a[3] = (v>>24)&0xff;
188   
189   swf_ResetWriteBits(t);
190   if ((t->len+4)>t->memsize) return (swf_SetBlock(t,a,4)==4)?0:-1;
191   t->data[t->len++] = a[0];
192   t->data[t->len++] = a[1];
193   t->data[t->len++] = a[2];
194   t->data[t->len++] = a[3];
195   return 0;
196 }
197
198 U32 swf_GetBits(TAG * t,int nbits)
199 { U32 res = 0;
200   if (!nbits) return 0;
201   if (!t->readBit) t->readBit = 0x80;
202   while (nbits)
203   { res<<=1;
204     if (t->data[t->pos]&t->readBit) res|=1;
205     t->readBit>>=1;
206     nbits--;
207     if (!t->readBit)
208     { if (nbits) t->readBit = 0x80;
209       #ifdef DEBUG_RFXSWF
210       if (t->pos>=t->len) 
211       { fprintf(stderr,"GetBits() out of bounds: TagID = %i\n",t->id);
212         return res;
213       }
214       #endif
215       t->pos++;
216     }
217   }
218   return res;
219 }
220
221 S32 swf_GetSBits(TAG * t,int nbits)
222 { U32 res = swf_GetBits(t,nbits);
223   if (res&(1<<(nbits-1))) res|=(0xffffffff<<nbits);  
224   return (S32)res;
225 }
226
227 U32 reader_GetBits(struct reader_t*reader, int nbits)
228 { return reader_readbits(reader, nbits);
229 }
230 S32 reader_GetSBits(struct reader_t*reader, int nbits)
231 { U32 res = reader_readbits(reader, nbits);
232   if (res&(1<<(nbits-1))) res|=(0xffffffff<<nbits);  
233   return (S32)res;
234 }
235
236 int swf_SetBits(TAG * t,U32 v,int nbits)
237 { U32 bm = 1<<(nbits-1);
238
239   while (nbits)
240   { if (!t->writeBit)
241     { if (FAILED(swf_SetU8(t,0))) return -1;
242       t->writeBit = 0x80;
243     }
244     if (v&bm) t->data[t->len-1] |= t->writeBit;
245     bm>>=1;
246     t->writeBit>>=1;
247     nbits--;
248   }
249   return 0;
250 }
251
252 // Advanced Data Access Functions
253
254 int swf_SetRGB(TAG * t,RGBA * col)
255 { if (!t) return -1;
256   if (col)
257   { swf_SetU8(t,col->r);
258     swf_SetU8(t,col->g);
259     swf_SetU8(t,col->b);
260   } else swf_SetBlock(t,NULL,3);
261   return 0;
262 }
263 void swf_GetRGB(TAG * t, RGBA * col)
264 {
265     RGBA dummy;
266     if(!col)
267         col = &dummy;
268     col->r = swf_GetU8(t);
269     col->g = swf_GetU8(t);
270     col->b = swf_GetU8(t);
271     col->a = 255;
272 }
273
274 int swf_SetRGBA(TAG * t,RGBA * col)
275 { if (!t) return -1;
276   if (col)
277   { swf_SetU8(t,col->r);
278     swf_SetU8(t,col->g);
279     swf_SetU8(t,col->b);
280     swf_SetU8(t,col->a);
281   } else swf_SetBlock(t,NULL,4);
282   return 0;
283 }
284 void swf_GetRGBA(TAG * t, RGBA * col)
285 {
286     RGBA dummy;
287     if(!col)
288         col = &dummy;
289     col->r = swf_GetU8(t);
290     col->g = swf_GetU8(t);
291     col->b = swf_GetU8(t);
292     col->a = swf_GetU8(t);
293 }
294
295 void swf_GetGradient(TAG * tag, GRADIENT * gradient, char alpha)
296 {
297     GRADIENT dummy;
298     int t;
299     if(!tag) {
300       memset(gradient, 0, sizeof(GRADIENT));
301       return;
302     }
303     if(!gradient)
304         gradient = &dummy;
305     gradient->num = swf_GetU8(tag);
306     for(t=0;t<gradient->num;t++)
307     {
308         int s=t;
309         if(s>=8) //FIXME
310             s=7;
311         gradient->ratios[t] = swf_GetU8(tag);
312         if(!alpha)
313             swf_GetRGB(tag, &gradient->rgba[t]);
314         else
315             swf_GetRGBA(tag, &gradient->rgba[t]);
316     }
317 }
318
319 void swf_SetGradient(TAG * tag, GRADIENT * gradient, char alpha)
320 {
321     int t;
322     if(!tag) {
323       memset(gradient, 0, sizeof(GRADIENT));
324       return;
325     }
326     swf_SetU8(tag, gradient->num);
327     for(t=0; t<8 && t<gradient->num; t++)
328     {
329         swf_SetU8(tag, gradient->ratios[t]);
330         if(!alpha)
331             swf_SetRGB(tag, &gradient->rgba[t]);
332         else
333             swf_SetRGBA(tag, &gradient->rgba[t]);
334     }
335 }
336
337 int swf_CountUBits(U32 v,int nbits)
338 { int n = 32;
339   U32 m = 0x80000000;
340   if(v == 0x00000000) n = 0; 
341   else
342     while (!(v&m))
343     { n--;
344       m>>=1;
345     } 
346   return (n>nbits)?n:nbits;
347 }
348
349 int swf_CountBits(U32 v,int nbits)
350 { int n = 33;
351   U32 m = 0x80000000;
352   if (v&m)
353   { if(v == 0xffffffff) n = 1;
354     else 
355     while (v&m)
356     { n--;
357       m>>=1;
358     } 
359   }
360   else
361   { if(v == 0x00000000) n = 0; 
362     else
363     while (!(v&m))
364     { n--;
365       m>>=1;
366     } 
367   }
368   return (n>nbits)?n:nbits;
369 }
370
371 int swf_GetRect(TAG * t,SRECT * r)
372 { int nbits;
373   SRECT dummy;
374   if(!t) {r->xmin=r->xmax=r->ymin=r->ymax=0;return 0;}
375   if (!r) r = &dummy;
376   nbits = (int) swf_GetBits(t,5);
377   r->xmin = swf_GetSBits(t,nbits);
378   r->xmax = swf_GetSBits(t,nbits);
379   r->ymin = swf_GetSBits(t,nbits);
380   r->ymax = swf_GetSBits(t,nbits);
381   return 0;
382 }
383
384 int reader_GetRect(struct reader_t*reader,SRECT * r)
385 { int nbits;
386   SRECT dummy;
387   if (!r) r = &dummy;
388   nbits = (int) reader_GetBits(reader,5);
389   r->xmin = reader_GetSBits(reader,nbits);
390   r->xmax = reader_GetSBits(reader,nbits);
391   r->ymin = reader_GetSBits(reader,nbits);
392   r->ymax = reader_GetSBits(reader,nbits);
393   return 0;
394 }
395
396 int swf_SetRect(TAG * t,SRECT * r)
397 { int nbits;
398     
399   nbits = swf_CountBits(r->xmin,0);
400   nbits = swf_CountBits(r->xmax,nbits);
401   nbits = swf_CountBits(r->ymin,nbits);
402   nbits = swf_CountBits(r->ymax,nbits);
403   if(nbits>=32) {
404     fprintf(stderr, "rfxswf: Warning: num_bits overflow in swf_SetRect\n");
405     nbits=31;
406   }
407
408   swf_SetBits(t,nbits,5);
409   swf_SetBits(t,r->xmin,nbits);
410   swf_SetBits(t,r->xmax,nbits);
411   swf_SetBits(t,r->ymin,nbits);
412   swf_SetBits(t,r->ymax,nbits);
413
414   return 0;
415 }
416
417 void swf_ExpandRect(SRECT*src, SPOINT add)
418 {
419     if((src->xmin | src->ymin | src->xmax | src->ymax)==0) {
420         src->xmin = add.x;
421         src->ymin = add.y;
422         src->xmax = add.x;
423         src->ymax = add.y;
424         if((add.x|add.y) == 0) src->xmax++; //make sure the bbox is not NULL anymore
425         return;
426     }
427     if(add.x < src->xmin)
428         src->xmin = add.x;
429     if(add.x > src->xmax)
430         src->xmax = add.x;
431     if(add.y < src->ymin)
432         src->ymin = add.y;
433     if(add.y > src->ymax)
434         src->ymax = add.y;
435 }
436 void swf_ExpandRect2(SRECT*src, SRECT*add)
437 {
438     if((add->xmin | add->ymin | add->xmax | add->ymax)==0)
439         return;
440     if((src->xmin | src->ymin | src->xmax | src->ymax)==0)
441         *src = *add;
442     if(add->xmin < src->xmin)
443         src->xmin = add->xmin;
444     if(add->ymin < src->ymin)
445         src->ymin = add->ymin;
446     if(add->xmax > src->xmax)
447         src->xmax = add->xmax;
448     if(add->ymax > src->ymax)
449         src->ymax = add->ymax;
450 }
451 void swf_ExpandRect3(SRECT*src, SPOINT center, int radius)
452 {
453     if((src->xmin | src->ymin | src->xmax | src->ymax)==0) {
454         src->xmin = center.x-radius;
455         src->ymin = center.y-radius;
456         src->xmax = center.x+radius;
457         src->ymax = center.y+radius;
458         if((center.x|center.y|radius) == 0) src->xmax++; //make sure the bbox is not NULL anymore
459         return;
460     }
461     if(center.x - radius < src->xmin)
462         src->xmin = center.x - radius;
463     if(center.x + radius > src->xmax)
464         src->xmax = center.x + radius;
465     if(center.y - radius < src->ymin)
466         src->ymin = center.y - radius;
467     if(center.y + radius > src->ymax)
468         src->ymax = center.y + radius;
469 }
470 SPOINT swf_TurnPoint(SPOINT p, MATRIX* m)
471 {
472     SPOINT r;
473     r.x = (int)(m->sx*(1/65536.0)*p.x + m->r1*(1/65536.0)*p.y + 0.5) + m->tx;
474     r.y = (int)(m->r0*(1/65536.0)*p.x + m->sy*(1/65536.0)*p.y + 0.5) + m->ty;
475     return r;
476 }
477 SRECT swf_TurnRect(SRECT r, MATRIX* m)
478 {
479     SRECT g;
480     SPOINT p1,p2,p3,p4,pp1,pp2,pp3,pp4;
481     if(!m)
482       return r;
483     p1.x = r.xmin;p1.y = r.ymin;
484     p2.x = r.xmax;p2.y = r.ymin;
485     p3.x = r.xmin;p3.y = r.ymax;
486     p4.x = r.xmax;p4.y = r.ymax;
487     pp1 = swf_TurnPoint(p1, m);
488     pp2 = swf_TurnPoint(p2, m);
489     pp3 = swf_TurnPoint(p3, m);
490     pp4 = swf_TurnPoint(p4, m);
491     g.xmin = g.xmax = pp1.x;
492     g.ymin = g.ymax = pp1.y;
493     swf_ExpandRect(&g, pp2);
494     swf_ExpandRect(&g, pp3);
495     swf_ExpandRect(&g, pp4);
496     return g;
497 }
498         
499
500 int swf_GetMatrix(TAG * t,MATRIX * m)
501 { MATRIX dummy;
502   int nbits;
503     
504   if (!m) m = &dummy;
505   
506   if (!t)
507   { m->sx = m->sy = 0x10000;
508     m->r0 = m->r1 = 0;
509     m->tx = m->ty = 0;
510     return -1;
511   }
512
513   swf_ResetReadBits(t);
514   
515   if (swf_GetBits(t,1))
516   { nbits = swf_GetBits(t,5);
517     m->sx = swf_GetSBits(t,nbits);
518     m->sy = swf_GetSBits(t,nbits);
519   }
520   else m->sx = m->sy = 0x10000;
521   
522   if (swf_GetBits(t,1))
523   { nbits = swf_GetBits(t,5);
524     m->r0 = swf_GetSBits(t,nbits);
525     m->r1 = swf_GetSBits(t,nbits);
526   }
527   else m->r0 = m->r1 = 0x0;
528
529   nbits = swf_GetBits(t,5);
530   m->tx = swf_GetSBits(t,nbits);
531   m->ty = swf_GetSBits(t,nbits);
532   
533   return 0;
534 }
535
536 int swf_SetMatrix(TAG * t,MATRIX * m)
537 { int nbits;
538   MATRIX ma;
539
540   if (!m)
541   { m = &ma;
542     ma.sx = ma.sy = 0x10000;
543     ma.r0 = ma.r1 = 0;
544     ma.tx = ma.ty = 0;
545   }
546
547   swf_ResetWriteBits(t);
548
549   if ((m->sx==0x10000)&&(m->sy==0x10000)) swf_SetBits(t,0,1);
550   else
551   { swf_SetBits(t,1,1);
552     nbits = swf_CountBits(m->sx,0);
553     nbits = swf_CountBits(m->sy,nbits);
554     if(nbits>=32) {
555         /* TODO: happens on AMD64 systems for normal values? */
556         fprintf(stderr,"rfxswf: Error: matrix values too large\n");
557         nbits = 31;
558     }
559     swf_SetBits(t,nbits,5);
560     swf_SetBits(t,m->sx,nbits);
561     swf_SetBits(t,m->sy,nbits);
562   }
563
564   if ((!m->r0)&&(!m->r1)) swf_SetBits(t,0,1);
565   else
566   { swf_SetBits(t,1,1);
567     nbits = swf_CountBits(m->r0,0);
568     nbits = swf_CountBits(m->r1,nbits);
569     if(nbits>=32) {
570         fprintf(stderr,"rfxswf: Error: matrix values too large\n");
571         nbits = 31;
572     }
573     swf_SetBits(t,nbits,5);
574     swf_SetBits(t,m->r0,nbits);
575     swf_SetBits(t,m->r1,nbits);
576   }
577
578   nbits = swf_CountBits(m->tx,0);
579   nbits = swf_CountBits(m->ty,nbits);
580   if(nbits>=32) {
581       fprintf(stderr,"rfxswf: Error: matrix values too large\n");
582       nbits = 31;
583   }
584   swf_SetBits(t,nbits,5);
585   swf_SetBits(t,m->tx,nbits);
586   swf_SetBits(t,m->ty,nbits);
587
588   return 0;
589 }
590
591 int swf_GetCXForm(TAG * t,CXFORM * cx,U8 alpha)
592 { CXFORM cxf;
593   int hasadd;
594   int hasmul;
595   int nbits;
596     
597   if (!cx) cx = &cxf;
598   
599   cx->a0 = cx->r0 = cx->g0 = cx->b0 = 256;
600   cx->a1 = cx->r1 = cx->g1 = cx->b1 = 0;
601
602   if (!t) return 0;
603   
604   swf_ResetReadBits(t);
605   hasadd = swf_GetBits(t,1);
606   hasmul = swf_GetBits(t,1);
607   nbits  = swf_GetBits(t,4);
608
609   if (hasmul)
610   { cx->r0 = (S16)swf_GetSBits(t,nbits);
611     cx->g0 = (S16)swf_GetSBits(t,nbits);
612     cx->b0 = (S16)swf_GetSBits(t,nbits);
613     if (alpha)
614       cx->a0 = (S16)swf_GetSBits(t,nbits);
615   }
616
617   if (hasadd)
618   { cx->r1 = (S16)swf_GetSBits(t,nbits);
619     cx->g1 = (S16)swf_GetSBits(t,nbits);
620     cx->b1 = (S16)swf_GetSBits(t,nbits);
621     if (alpha)
622       cx->a1 = (S16)swf_GetSBits(t,nbits);
623   }
624   
625   return 0;
626 }
627
628 int swf_SetCXForm(TAG * t,CXFORM * cx,U8 alpha)
629 { CXFORM cxf;
630   int hasadd;
631   int hasmul;
632   int nbits;
633     
634   if (!cx)
635   { cx = &cxf;
636     cx->a0 = cx->r0 = cx->g0 = cx->b0 = 256;
637     cx->a1 = cx->r1 = cx->g1 = cx->b1 = 0;
638   }
639
640   if (!alpha)
641   { cx->a0 = 256;
642     cx->a1 = 0;
643   }
644
645   nbits = 0;
646
647   hasmul = (cx->a0!=256)||(cx->r0!=256)||(cx->g0!=256)||(cx->b0!=256);
648   hasadd = cx->a1|cx->r1|cx->g1|cx->b1;
649
650   if (hasmul)
651   { if (alpha) nbits = swf_CountBits((S32)cx->a0,nbits);
652     nbits = swf_CountBits((S32)cx->r0,nbits);
653     nbits = swf_CountBits((S32)cx->g0,nbits);
654     nbits = swf_CountBits((S32)cx->b0,nbits);
655   }
656
657   if (hasadd)
658   { if (alpha) nbits = swf_CountBits((S32)cx->a1,nbits);
659     nbits = swf_CountBits((S32)cx->r1,nbits);
660     nbits = swf_CountBits((S32)cx->g1,nbits);
661     nbits = swf_CountBits((S32)cx->b1,nbits);
662   }
663   
664   swf_ResetWriteBits(t);
665   swf_SetBits(t,hasadd?1:0,1);
666   swf_SetBits(t,hasmul?1:0,1);
667   swf_SetBits(t,nbits,4);
668
669   if (hasmul)
670   { swf_SetBits(t,cx->r0,nbits);
671     swf_SetBits(t,cx->g0,nbits);
672     swf_SetBits(t,cx->b0,nbits);
673     if (alpha) swf_SetBits(t,cx->a0,nbits);
674   }
675
676   if (hasadd)
677   { swf_SetBits(t,cx->r1,nbits);
678     swf_SetBits(t,cx->g1,nbits);
679     swf_SetBits(t,cx->b1,nbits);
680     if (alpha) swf_SetBits(t,cx->a1,nbits);
681   }
682   
683   return 0;
684 }
685
686 //int swf_GetPoint(TAG * t,SPOINT * p) { return 0; }
687 //int swf_SetPoint(TAG * t,SPOINT * p) { return 0; }
688
689 void  swf_SetPassword(TAG * t, const char * password)
690 {
691     /* WARNING: crypt_md5 is not reentrant */
692     char salt[3];
693     char* md5string;
694
695 #if defined(HAVE_LRAND48) && defined(HAVE_SRAND48) && defined(HAVE_TIME_H) && defined(HAVE_TIME)
696     srand48(time(0));
697     salt[0] = "abcdefghijklmnopqrstuvwxyz0123456789"[lrand48()%36];
698     salt[1] = "abcdefghijklmnopqrstuvwxyz0123456789"[lrand48()%36];
699 #else
700     salt[0] = 'l';
701     salt[1] = '8';
702     fprintf(stderr, "rfxswf: Warning- no usable random generator found\n");
703     fprintf(stderr, "Your password will be vulnerable to dictionary attacks\n");
704 #endif
705     salt[2] = 0;
706     
707     md5string = crypt_md5(password, salt);
708
709     swf_SetU16(t,0);
710     swf_SetString(t, md5string);
711 }
712
713 int swf_VerifyPassword(TAG * t, const char * password)
714 {
715     char*md5string1, *md5string2;
716     char*x;
717     char*md5, *salt;
718     int n;
719
720     if(t->len >= 5 && t->pos==0 && 
721        t->data[0] == 0 &&
722        t->data[1] == 0) {
723       swf_GetU16(t);
724     } else {
725       printf("%d %d %d %d\n", t->len, t->pos, t->data[0], t->data[1]);
726     }
727
728     md5string1 = swf_GetString(t);
729
730     if(strncmp(md5string1, "$1$",3 )) {
731         fprintf(stderr, "rfxswf: no salt in pw string\n");
732         return 0;
733     }
734     x = strchr(md5string1+3, '$');
735     if(!x) {
736         fprintf(stderr, "rfxswf: invalid salt format in pw string\n");
737         return 0;
738     }
739     n = x-(md5string1+3);
740     salt = (char*)rfx_alloc(n+1);
741     memcpy(salt, md5string1+3, n);
742     salt[n] = 0;
743
744     md5string2 = crypt_md5(password, salt);
745     rfx_free(salt);
746     if(strcmp(md5string1, md5string2) != 0)
747         return 0;
748     return 1;
749 }
750
751 // Tag List Manipulating Functions
752
753 TAG * swf_InsertTag(TAG * after,U16 id)
754 { TAG * t;
755
756   t = (TAG *)rfx_calloc(sizeof(TAG));
757   t->id = id;
758   
759   if (after)
760   {
761     t->prev  = after;
762     t->next  = after->next;
763     after->next = t;
764     if (t->next) t->next->prev = t;
765   }
766   return t;
767 }
768
769 TAG * swf_InsertTagBefore(SWF* swf, TAG * before,U16 id)
770 { TAG * t;
771
772   t = (TAG *)rfx_calloc(sizeof(TAG));
773   t->id = id;
774   
775   if (before)
776   {
777     t->next  = before;
778     t->prev  = before->prev;
779     before->prev = t;
780     if (t->prev) t->prev->next = t;
781   }
782   if(swf && swf->firstTag == before) {
783     swf->firstTag = t;
784   }
785   return t;
786 }
787
788 void swf_ClearTag(TAG * t)
789 {
790   if (t->data) rfx_free(t->data);
791   t->data = 0;
792   t->pos = 0;
793   t->len = 0;
794   t->readBit = 0;
795   t->writeBit = 0;
796   t->memsize = 0;
797 }
798
799 void swf_ResetTag(TAG*tag, U16 id)
800 {
801     tag->len = tag->pos = tag->readBit = tag->writeBit = 0;
802     tag->id = id;
803 }
804
805 TAG* swf_CopyTag(TAG*tag, TAG*to_copy)
806 {
807     tag = swf_InsertTag(tag, to_copy->id);
808     swf_SetBlock(tag, to_copy->data, to_copy->len);
809     return tag;
810 }
811
812 int swf_DeleteTag(TAG * t)
813 { if (!t) return -1;
814
815   if (t->prev) t->prev->next = t->next;
816   if (t->next) t->next->prev = t->prev;
817
818   if (t->data) rfx_free(t->data);
819   rfx_free(t);
820   return 0;
821 }
822
823 TAG * swf_ReadTag(struct reader_t*reader, TAG * prev)
824 { TAG * t;
825   U16 raw;
826   U32 len;
827   int id;
828
829   if (reader->read(reader, &raw, 2) !=2 ) return NULL;
830   raw = SWAP16(raw);
831
832   len = raw&0x3f;
833   id  = raw>>6;
834
835   if (len==0x3f)
836   {
837       if (reader->read(reader, &len, 4) != 4) return NULL;
838       len = SWAP32(len);
839   }
840
841   if (id==ST_DEFINESPRITE) len = 2*sizeof(U16);
842   // Sprite handling fix: Flatten sprite tree
843
844   t = (TAG *)rfx_calloc(sizeof(TAG));
845   
846   t->len = len;
847   t->id  = id;
848
849   if (t->len)
850   { t->data = (U8*)rfx_alloc(t->len);
851     t->memsize = t->len;
852     if (reader->read(reader, t->data, t->len) != t->len) {
853       fprintf(stderr, "rfxswf: Warning: Short read (tagid %d). File truncated?\n", t->id);
854       free(t->data);t->data=0;
855       free(t);
856       return NULL;
857     }
858   }
859
860   if (prev)
861   {
862     t->prev  = prev;
863     prev->next = t;
864   }
865
866   return t;
867 }
868
869 int swf_DefineSprite_GetRealSize(TAG * t);
870
871 int swf_WriteTag2(struct writer_t*writer, TAG * t)
872 // returns tag length in bytes (incl. Header), -1 = Error
873 // writer = 0 -> no output
874 { U16 raw[3];
875   U32 len;
876   int short_tag;
877
878   if (!t) return -1;
879
880   len = (t->id==ST_DEFINESPRITE)?swf_DefineSprite_GetRealSize(t):t->len;
881
882   short_tag = len<0x3f&&
883     (t->id!=ST_DEFINEBITSLOSSLESS&&t->id!=ST_DEFINEBITSLOSSLESS2&&t->id!=ST_SOUNDSTREAMBLOCK&&
884      t->id!=ST_DEFINEBITSJPEG&&t->id!=ST_DEFINEBITSJPEG2&&t->id!=ST_DEFINEBITSJPEG3);
885
886   if (writer)
887   { if (short_tag)
888     { raw[0] = SWAP16(len|((t->id&0x3ff)<<6));
889       if (writer->write(writer,raw,2)!=2)
890       {
891         #ifdef DEBUG_RFXSWF
892           fprintf(stderr,"WriteTag() failed: Short Header.\n");
893         #endif
894         return -1;
895       }
896     }
897     else
898     {
899       raw[0] = SWAP16((t->id<<6)|0x3f);
900       if (writer->write(writer,raw,2)!=2)
901       {
902 #ifdef DEBUG_RFXSWF
903           fprintf(stderr,"WriteTag() failed: Long Header (1).\n");
904 #endif
905           return -1;
906       }
907       
908       len = SWAP32(len);
909       if (writer->write(writer,&len,4)!=4)
910       {
911         #ifdef DEBUG_RFXSWF
912           fprintf(stderr,"WriteTag() failed: Long Header (2).\n");
913         #endif
914         return -1;
915       }
916     }
917     
918     if (t->data)
919     { if (writer->write(writer,t->data,t->len)!=t->len)
920       {
921         #ifdef DEBUG_RFXSWF
922           fprintf(stderr,"WriteTag() failed: Data.\n");
923         #endif
924         return -1;
925       }
926     }
927     #ifdef DEBUG_RFXSWF
928       else if (t->len) fprintf(stderr,"WriteTag(): Tag Data Error, id=%i\n",t->id);
929     #endif
930   }
931
932   return t->len+(short_tag?2:6);
933 }
934
935 int swf_WriteTag(int handle, TAG * t)
936 {
937   struct writer_t writer;
938   int len = 0;
939   if(handle<0)
940     return swf_WriteTag2(0, t);
941   writer_init_filewriter(&writer, handle);
942   len = swf_WriteTag2(&writer, t);
943   writer.finish(&writer);
944   return len;
945 }
946
947 int swf_DefineSprite_GetRealSize(TAG * t)
948 // Sprite Handling: Helper function to pack DefineSprite-Tag
949 { U32 len = t->len;
950   if(len>4) { // folded sprite
951       return t->len;
952   }
953   do
954   { t = swf_NextTag(t);
955     if (t && t->id!=ST_DEFINESPRITE) len += swf_WriteTag(-1, t);
956     else t = NULL;
957   } while (t&&(t->id!=ST_END));
958   return len;
959 }
960
961 void swf_UnFoldSprite(TAG * t)
962 {
963   U16 id,tmp;
964   U32 len;
965   TAG*next = t;
966   U16 spriteid,spriteframes;
967   int level;
968   if(t->id!=ST_DEFINESPRITE)
969     return;
970   if(t->len<=4) // not folded
971     return;
972
973   swf_SetTagPos(t,0);
974
975   spriteid = swf_GetU16(t); //id
976   spriteframes = swf_GetU16(t); //frames
977
978   level = 1;
979
980   while(1)
981   {
982     TAG*it = 0;
983     tmp = swf_GetU16(t);
984     len = tmp&0x3f;
985     id  = tmp>>6;
986     if(id == ST_END)
987         level--;
988     if(id == ST_DEFINESPRITE && len<=4)
989         level++;
990
991     if (len==0x3f)
992         len = swf_GetU32(t);
993     it = swf_InsertTag(next, id);
994     next = it;
995     it->len = len;
996     it->id  = id;
997     if (it->len)
998     { it->data = (U8*)rfx_alloc(it->len);
999       it->memsize = it->len;
1000       swf_GetBlock(t, it->data, it->len);
1001     }
1002
1003     if(!level)
1004         break;
1005   }
1006   
1007   rfx_free(t->data); t->data = 0;
1008   t->memsize = t->len = t->pos = 0;
1009
1010   swf_SetU16(t, spriteid);
1011   swf_SetU16(t, spriteframes);
1012 }
1013
1014 void swf_FoldSprite(TAG * t)
1015 {
1016   TAG*sprtag=t,*tmp;
1017   U16 id,frames,tmpid;
1018   int level;
1019   if(t->id!=ST_DEFINESPRITE)
1020       return;
1021   if(!t->len) {
1022       fprintf(stderr, "Error: Sprite has no ID!");
1023       return;
1024   }
1025   if(t->len>4) {
1026     /* sprite is already folded */
1027       return;
1028   }
1029
1030   t->pos = 0;
1031   id = swf_GetU16(t);
1032   rfx_free(t->data);
1033   t->len = t->pos = t->memsize = 0;
1034   t->data = 0;
1035
1036   frames = 0;
1037
1038   t = swf_NextTag(sprtag);
1039   level = 1;
1040
1041   do 
1042   { 
1043     if(t->id==ST_SHOWFRAME) frames++;
1044     if(t->id == ST_DEFINESPRITE && t->len<=4)
1045         level++;
1046     if(t->id == ST_END)
1047         level--;
1048     t = swf_NextTag(t);
1049   } while(t && level);
1050   if(level)
1051     fprintf(stderr, "rfxswf error: sprite doesn't end(1)\n");
1052
1053   swf_SetU16(sprtag, id);
1054   swf_SetU16(sprtag, frames);
1055
1056   t = swf_NextTag(sprtag);
1057   level = 1;
1058
1059   do
1060   { 
1061     if(t->len<0x3f&&
1062         (t->id!=ST_DEFINEBITSLOSSLESS&&t->id!=ST_DEFINEBITSLOSSLESS2&&t->id!=ST_SOUNDSTREAMBLOCK&&
1063          t->id!=ST_DEFINEBITSJPEG&&t->id!=ST_DEFINEBITSJPEG2&&t->id!=ST_DEFINEBITSJPEG3)
1064       ) {
1065         swf_SetU16(sprtag,t->len|(t->id<<6));
1066     } else {
1067         swf_SetU16(sprtag,0x3f|(t->id<<6));
1068         swf_SetU32(sprtag,t->len);
1069     }
1070     if(t->len)
1071         swf_SetBlock(sprtag,t->data, t->len);
1072     tmp = t;
1073     if(t->id == ST_DEFINESPRITE && t->len<=4)
1074         level++;
1075     if(t->id == ST_END)
1076         level--;
1077     t = swf_NextTag(t);
1078     swf_DeleteTag(tmp);
1079   } 
1080   while (t && level);
1081   if(level)
1082     fprintf(stderr, "rfxswf error: sprite doesn't end(2)\n");
1083
1084 //  sprtag->next = t;
1085 //  t->prev = sprtag;
1086 }
1087
1088 int swf_IsFolded(TAG * t)
1089 {
1090     return (t->id == ST_DEFINESPRITE && t->len>4);
1091 }
1092
1093 void swf_FoldAll(SWF*swf)
1094 {
1095     TAG*tag = swf->firstTag;
1096     //swf_DumpSWF(stdout, swf);
1097     while(tag) {
1098         if(tag->id == ST_DEFINESPRITE) {
1099             swf_FoldSprite(tag);
1100             //swf_DumpSWF(stdout, swf);
1101         }
1102         tag = swf_NextTag(tag);
1103     }
1104 }
1105
1106 void swf_UnFoldAll(SWF*swf)
1107 {
1108     TAG*tag = swf->firstTag;
1109     while(tag) {
1110         if(tag->id == ST_DEFINESPRITE)
1111             swf_UnFoldSprite(tag);
1112         tag = tag->next;
1113     }
1114 }
1115
1116 void swf_OptimizeTagOrder(SWF*swf)
1117 {
1118   TAG*tag,*next;
1119   TAG*level0;
1120   int level;
1121   int changes;
1122   swf_UnFoldAll(swf);
1123   /* at the moment, we don't actually do optimizing,
1124      only fixing of non-spec-conformant things like
1125      sprite tags */
1126
1127   do {
1128     changes = 0;
1129     level = 0;
1130     level0 = 0;
1131     tag = swf->firstTag;
1132     while(tag) {
1133       next = tag->next;
1134       if(tag->id == ST_DEFINESPRITE) {
1135         if(tag->len>4) {
1136           /* ??? all sprites are supposed to be unfolded */
1137           fprintf(stderr, "librfxswf error - internal error in OptimizeTagOrder/UnfoldAll\n");
1138         }
1139         level++;
1140         if(level==1) {
1141           level0 = tag;
1142           tag = next;
1143           continue;
1144         }
1145       }
1146       if(level>=1) {
1147         /* move non-sprite tags out of sprite */
1148         if(!swf_isAllowedSpriteTag(tag) || level>=2) {
1149           /* remove tag from current position */
1150           tag->prev->next = tag->next;
1151           if(tag->next)
1152             tag->next->prev = tag->prev;
1153
1154           /* insert before tag level0 */
1155           tag->next = level0;
1156           tag->prev = level0->prev;
1157           level0->prev = tag;
1158           if(tag->prev)
1159             tag->prev->next = tag;
1160           else
1161             swf->firstTag = tag;
1162           changes = 1;
1163         }
1164       }
1165       if(tag->id == ST_END) {
1166         level--;
1167       }
1168
1169       tag = next;
1170     }
1171   } while(changes);
1172 }
1173
1174 // Movie Functions
1175
1176 int swf_ReadSWF2(struct reader_t*reader, SWF * swf)   // Reads SWF to memory (malloc'ed), returns length or <0 if fails
1177 {     
1178   if (!swf) return -1;
1179   memset(swf,0x00,sizeof(SWF));
1180
1181   { char b[32];                         // read Header
1182     int len;
1183     TAG * t;
1184     TAG t1;
1185     struct reader_t zreader;
1186     
1187     if ((len = reader->read(reader ,b,8))<8) return -1;
1188
1189     if (b[0]!='F' && b[0]!='C') return -1;
1190     if (b[1]!='W') return -1;
1191     if (b[2]!='S') return -1;
1192     swf->fileVersion = b[3];
1193     swf->compressed  = (b[0]=='C')?1:0;
1194     swf->fileSize    = GET32(&b[4]);
1195     
1196     if(swf->compressed) {
1197         reader_init_zlibinflate(&zreader, reader);
1198         reader = &zreader;
1199     }
1200
1201     reader_GetRect(reader, &swf->movieSize);
1202     reader->read(reader, &swf->frameRate, 2);
1203     swf->frameRate = SWAP16(swf->frameRate);
1204     reader->read(reader, &swf->frameCount, 2);
1205     swf->frameCount = SWAP16(swf->frameCount);
1206
1207     /* read tags and connect to list */
1208     t = &t1;
1209     while (t) t = swf_ReadTag(reader,t);
1210     swf->firstTag = t1.next;
1211     t1.next->prev = NULL;
1212   }
1213   
1214   return reader->pos;
1215 }
1216
1217 int swf_ReadSWF(int handle, SWF * swf)
1218 {
1219   struct reader_t reader;
1220   reader_init_filereader(&reader, handle);
1221   return swf_ReadSWF2(&reader, swf);
1222 }
1223
1224 int  swf_WriteSWF2(struct writer_t*writer, SWF * swf)     // Writes SWF to file, returns length or <0 if fails
1225 { U32 len;
1226   TAG * t;
1227   int frameCount=0;
1228   struct writer_t zwriter;
1229   int fileSize = 0;
1230   int inSprite = 0;
1231   int writer_lastpos = 0;
1232   int ret;
1233     
1234   if (!swf) return -1;
1235   if (!writer) return -1; // the caller should provide a nullwriter, not 0, for querying SWF size
1236
1237   if(writer) writer_lastpos = writer->pos;
1238
1239   // Insert REFLEX Tag
1240
1241 #ifdef INSERT_RFX_TAG
1242
1243   if ((swf->firstTag && swf->firstTag->id != ST_REFLEX) &&
1244       (!swf->firstTag->next || swf->firstTag->next->id != ST_REFLEX)) 
1245   {
1246       swf_SetBlock(swf_InsertTagBefore(swf, swf->firstTag,ST_REFLEX),"rfx",3);
1247   }
1248
1249 #endif // INSERT_RFX_TAG
1250
1251   // Count Frames + File Size
1252
1253   len = 0;
1254   t = swf->firstTag;
1255   frameCount = 0;
1256
1257   while(t) {
1258       len += swf_WriteTag(-1,t);
1259       if(t->id == ST_DEFINESPRITE && !swf_IsFolded(t)) inSprite++;
1260       else if(t->id == ST_END && inSprite) inSprite--;
1261       else if(t->id == ST_END && !inSprite) {
1262         if(t->prev && t->prev->id!=ST_SHOWFRAME)
1263           frameCount++;
1264       }
1265       else if(t->id == ST_SHOWFRAME && !inSprite) frameCount++;
1266       t = swf_NextTag(t);
1267   }
1268   
1269   { TAG t1;
1270     char b[64],b4[4];
1271     U32 l;
1272
1273     memset(&t1,0x00,sizeof(TAG));
1274     t1.data    = (U8*)b;
1275     t1.memsize = 64;
1276     
1277     { // measure header file size
1278       TAG t2;
1279       char b2[64];
1280       memset(&t2,0x00,sizeof(TAG));
1281       t2.data    = (U8*)b2;
1282       t2.memsize = 64;
1283       swf_SetRect(&t2, &swf->movieSize);
1284       swf_SetU16(&t2, swf->frameRate);
1285       swf_SetU16(&t2, swf->frameCount);
1286       l = swf_GetTagLen(&t2)+8;
1287     }
1288     if(swf->compressed == 8) {
1289       l -= 8;
1290     }
1291
1292     fileSize = l+len;
1293     if(len) {// don't touch headers without tags
1294         swf->fileSize = fileSize;
1295         swf->frameCount = frameCount;
1296     }
1297
1298     if(swf->compressed != 8) {
1299     /* compressed flag set to 8 means "skip first 8 
1300        header bytes". This is necessary if the caller wants to
1301        create compressed SWFs himself .
1302        It also means that we don't initialize our own zlib
1303        writer, but assume the caller provided one.
1304      */
1305       if(swf->compressed) {
1306         char*id = "CWS";
1307         writer->write(writer, id, 3);
1308       }
1309       else {
1310         char*id = "FWS";
1311         writer->write(writer, id, 3);
1312       }
1313
1314       writer->write(writer, &swf->fileVersion, 1);
1315       PUT32(b4, swf->fileSize);
1316       writer->write(writer, b4, 4);
1317       
1318       if(swf->compressed) {
1319         writer_init_zlibdeflate(&zwriter, writer);
1320         writer = &zwriter;
1321       }
1322     }
1323
1324     swf_SetRect(&t1,&swf->movieSize);
1325     swf_SetU16(&t1,swf->frameRate);
1326     swf_SetU16(&t1,swf->frameCount);
1327
1328     ret = writer->write(writer,b,swf_GetTagLen(&t1));
1329     if (ret!=swf_GetTagLen(&t1))
1330     {
1331       #ifdef DEBUG_RFXSWF
1332         fprintf(stderr, "ret:%d\n",ret);
1333         perror("write:");
1334         fprintf(stderr,"WriteSWF() failed: Header.\n");
1335       #endif
1336       return -1;
1337     }
1338
1339     t = swf->firstTag;
1340     while (t)
1341     { if (swf_WriteTag2(writer, t)<0) return -1;
1342       t = swf_NextTag(t);
1343     }
1344     if(swf->compressed) {
1345       if(swf->compressed != 8) {
1346         zwriter.finish(&zwriter);
1347         return writer->pos - writer_lastpos;
1348       }
1349       return (int)fileSize;
1350     } else {
1351       return (int)fileSize;
1352     }
1353   }
1354 }
1355
1356 int  swf_WriteSWF(int handle, SWF * swf)     // Writes SWF to file, returns length or <0 if fails
1357 {
1358   struct writer_t writer;
1359   int len = 0;
1360   swf->compressed = 0;
1361   
1362   if(handle<0) {
1363     writer_init_nullwriter(&writer);
1364     len = swf_WriteSWF2(&writer, swf);
1365     return len;
1366   }
1367   writer_init_filewriter(&writer, handle);
1368   len = swf_WriteSWF2(&writer, swf);
1369   writer.finish(&writer);
1370   return len;
1371 }
1372
1373 int  swf_WriteSWC(int handle, SWF * swf)     // Writes SWF to file, returns length or <0 if fails
1374 {
1375   struct writer_t writer;
1376   int len = 0;
1377   swf->compressed = 1;
1378
1379   if(handle<0) {
1380     writer_init_nullwriter(&writer);
1381     len = swf_WriteSWF2(&writer, swf);
1382   }
1383   writer_init_filewriter(&writer, handle);
1384   len = swf_WriteSWF2(&writer, swf);
1385   writer.finish(&writer);
1386   return len;
1387 }
1388
1389 int swf_WriteHeader2(struct writer_t*writer,SWF * swf)
1390 {
1391   SWF myswf;
1392   memcpy(&myswf,swf,sizeof(SWF));
1393   myswf.firstTag = 0;
1394   return swf_WriteSWF2(writer, &myswf);
1395 }
1396
1397 int swf_WriteHeader(int handle,SWF * swf)
1398 {
1399   SWF myswf;
1400   memcpy(&myswf,swf,sizeof(SWF));
1401   myswf.firstTag = 0;
1402   return swf_WriteSWF(handle, &myswf);
1403 }
1404
1405 int swf_WriteCGI(SWF * swf)
1406 { int len;
1407   char s[1024];
1408     
1409   len = swf_WriteSWF(-1,swf);
1410
1411   if (len<0) return -1;
1412
1413   sprintf(s,"Content-type: application/x-shockwave-flash\n"
1414             "Accept-Ranges: bytes\n"
1415             "Content-Length: %lu\n"
1416             "Expires: Thu, 13 Apr 2000 23:59:59 GMT\n"
1417             "\n",len);
1418             
1419   write(fileno(stdout),s,strlen(s));
1420   return swf_WriteSWF(fileno(stdout),swf);
1421 }
1422
1423 SWF* swf_CopySWF(SWF*swf)
1424 {
1425     SWF*nswf = rfx_alloc(sizeof(SWF));
1426     TAG*tag, *ntag;
1427     memcpy(nswf, swf, sizeof(SWF));
1428     nswf->firstTag = 0;
1429     tag = swf->firstTag;
1430     ntag = 0;
1431     while(tag) {
1432         ntag = swf_CopyTag(ntag, tag);
1433         if(!nswf->firstTag)
1434             nswf->firstTag = ntag;
1435         tag = tag->next;
1436     }
1437     return nswf;
1438 }
1439
1440 void swf_FreeTags(SWF * swf)                 // Frees all malloc'ed memory for tags
1441 { TAG * t = swf->firstTag;
1442
1443   while (t)
1444   { TAG * tnew = t->next;
1445     if (t->data) rfx_free(t->data);
1446     rfx_free(t);
1447     t = tnew;
1448   }
1449   swf->firstTag = 0;
1450 }
1451
1452 // include advanced functions
1453
1454 #include "modules/swfdump.c"
1455 #include "modules/swfshape.c"
1456 #include "modules/swftext.c"
1457 #include "modules/swffont.c"
1458 #include "modules/swfobject.c"
1459 #include "modules/swfbutton.c"
1460 #include "modules/swftools.c"
1461 #include "modules/swfcgi.c"
1462 #include "modules/swfbits.c"
1463 #include "modules/swfaction.c"
1464 #include "modules/swfsound.c"
1465 #include "modules/swfdraw.c"
1466 #include "modules/swfrender.c"