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