implemented --framerate.
[swftools.git] / src / png2swf.c
1 /* png2swf.c
2
3    PNG to SWF converter tool
4
5    Part of the swftools package.
6
7    Copyright (c) 2002 Matthias Kramm <kramm@quiss.org>
8  
9    This file is distributed under the GPL, see file COPYING for details 
10
11 */
12
13 #include <stdio.h>
14 #include <math.h>
15 #include <fcntl.h>
16 #include <zlib.h>
17 #include "../lib/rfxswf.h"
18 #include "../lib/args.h"
19
20 #define MAX_INPUT_FILES 1024
21 #define VERBOSE(x) (global.verbose>=x)
22
23 struct {
24     int framerate;
25     int max_image_width;
26     int max_image_height;
27     int force_width;
28     int force_height;
29     int nfiles;
30     int verbose;
31     char *outfile;
32 } global;
33
34 struct {
35     char *filename;
36 } image[MAX_INPUT_FILES];
37
38 TAG *MovieStart(SWF * swf, int framerate, int dx, int dy)
39 {
40     TAG *t;
41     RGBA rgb;
42
43     memset(swf, 0x00, sizeof(SWF));
44
45     swf->fileVersion = 4;
46     swf->frameRate = (25600 / framerate);
47     swf->movieSize.xmax = dx * 20;
48     swf->movieSize.ymax = dy * 20;
49
50     t = swf->firstTag = swf_InsertTag(NULL, ST_SETBACKGROUNDCOLOR);
51
52     rgb.r = rgb.g = rgb.b = rgb.a = 0x00;
53     swf_SetRGB(t, &rgb);
54
55     return t;
56 }
57
58 int MovieFinish(SWF * swf, TAG * t, char *sname)
59 {
60     int handle, so = fileno(stdout);
61     t = swf_InsertTag(t, ST_END);
62
63     if ((!isatty(so)) && (!sname))
64         handle = so;
65     else {
66         if (!sname)
67             sname = "output.swf";
68         handle = open(sname, O_RDWR | O_CREAT | O_TRUNC, 0666);
69     }
70     if FAILED
71         (swf_WriteSWF(handle, swf)) if (VERBOSE(1))
72             fprintf(stderr, "Unable to write output file: %s\n", sname);
73     if (handle != so)
74         close(handle);
75
76     swf_FreeTags(swf);
77     return 0;
78 }
79
80 int png_read_chunk(char (*head)[4], int*destlen, U8**destdata, FILE*fi)
81 {
82     unsigned int len;
83     if(destlen) *destlen=0;
84     if(destdata) *destdata=0;
85     if(!fread(&len, 4, 1, fi))
86         return 0;
87     if(!fread(head, 4, 1, fi))
88         return 0;
89     len = REVERSESWAP32(len);
90     if(destlen) *destlen = len;
91     if(destdata) {
92         if(len)
93             *destdata = malloc(len);
94         else 
95             *destdata = 0;
96         if(!fread(*destdata, len, 1, fi)) {
97             *destdata = 0;
98             if(destlen) *destlen=0;
99             return 0;
100         }
101         fseek(fi, 4, SEEK_CUR);
102
103     } else {
104         fseek(fi, len+4, SEEK_CUR);
105     }
106     return 1;
107 }
108
109 unsigned int png_get_dword(FILE*fi)
110 {
111     unsigned int a;
112     fread(&a,4,1,fi);
113     return REVERSESWAP32(a);
114 }
115
116 struct png_header
117 {
118     int width;
119     int height;
120     int bpp;
121     int mode;
122 };
123
124 int png_read_header(FILE*fi, struct png_header*header)
125 {
126     char id[4];
127     int len;
128     int ok=0;
129     U8 head[8] = {137,80,78,71,13,10,26,10};
130     U8 head2[8];
131     U8*data;
132     fread(head2,8,1,fi);
133     if(strncmp(head,head2,4))
134         return 0;
135    
136     while(png_read_chunk(&id, &len, &data, fi))
137     {
138         if(VERBOSE(2))
139             printf("%c%c%c%c %d\n", id[0],id[1],id[2],id[3],len);
140         if(!strncasecmp(id, "IHDR", 4)) {
141             char a,b,c,f,i;
142             if(len < 8) exit(1);
143             header->width = REVERSESWAP32(*(U32*)&data[0]);
144             header->height = REVERSESWAP32(*(U32*)&data[4]);
145             a = data[8];      // should be 8
146             b = data[9];      // should be 3(indexed) or 2(rgb)
147
148             c = data[10];     // compression mode (0)
149             f = data[11];     // filter mode (0)
150             i = data[12];     // interlace mode (0)
151
152             if(b!=2 && b!=3 && b!=6) {
153                 fprintf(stderr, "Image mode %d not supported!\n", b);
154                 exit(1);
155             }
156             if(a!=8 && (b==2 || b==6)) {
157                 fprintf(stderr, "Bpp %d in mode %d not supported!\n", a);
158                 exit(1);
159             }
160             if(c!=0) {
161                 fprintf(stderr, "Compression mode %d not supported!\n", c);
162                 exit(1);
163             }
164             if(f!=0) {
165                 fprintf(stderr, "Filter mode %d not supported!\n", f);
166                 exit(1);
167             }
168             if(i!=0) {
169                 fprintf(stderr, "Interlace mode %d not supported!\n", i);
170                 exit(1);
171             }
172             if(VERBOSE(2))
173                 printf("%dx%d %d %d %d %d %d\n",header->width, header->height, a,b,c,f,i);
174             header->bpp = a;
175             header->mode = b;
176             ok = 1;
177         } 
178         
179         free(data);
180     }
181     return ok;
182 }
183
184 typedef unsigned char byte;
185 #define ABS(a) ((a)>0?(a):(-(a)))
186 byte inline PaethPredictor (byte a,byte b,byte c)
187 {
188         // a = left, b = above, c = upper left
189         int p = a + b - c;        // initial estimate
190         int pa = ABS(p - a);      // distances to a, b, c
191         int pb = ABS(p - b);
192         int pc = ABS(p - c);
193         // return nearest of a,b,c,
194         // breaking ties in order a,b,c.
195         if (pa <= pb && pa <= pc) 
196                 return a;
197         else if (pb <= pc) 
198                 return b;
199         else return c;
200 }
201
202 void applyfilter3(int mode, U8*src, U8*old, U8*dest, int width)
203 {
204     int x;
205     unsigned char lastr=0;
206     unsigned char lastg=0;
207     unsigned char lastb=0;
208     unsigned char upperlastr=0;
209     unsigned char upperlastg=0;
210     unsigned char upperlastb=0;
211
212     if(mode==0) {
213         for(x=0;x<width;x++) {
214             dest[0] = 255;
215             dest[1] = src[0];
216             dest[2] = src[1];
217             dest[3] = src[2];
218             dest+=4;
219             src+=3;
220         }
221     }
222     else if(mode==1) {
223         for(x=0;x<width;x++) {
224             dest[0] = 255;
225             dest[1] = src[0]+lastr;
226             dest[2] = src[1]+lastg;
227             dest[3] = src[2]+lastb;
228             lastr = dest[1];
229             lastg = dest[2];
230             lastb = dest[3];
231             dest+=4;
232             src+=3;
233         }
234     }
235     else if(mode==2) {
236         for(x=0;x<width;x++) {
237             dest[0] = 255;
238             dest[1] = src[0]+old[1];
239             dest[2] = src[1]+old[2];
240             dest[3] = src[2]+old[3];
241             dest+=4;
242             old+=4;
243             src+=3;
244         }
245     }
246     else if(mode==3) {
247         for(x=0;x<width;x++) {
248             dest[0] = 255;
249             dest[1] = src[0]+(old[1]+lastr)/2;
250             dest[2] = src[1]+(old[2]+lastg)/2;
251             dest[3] = src[2]+(old[3]+lastb)/2;
252             lastr = dest[1];
253             lastg = dest[2];
254             lastb = dest[3];
255             dest+=4;
256             old+=4;
257             src+=3;
258         }
259     }
260     else if(mode==4) {
261         for(x=0;x<width;x++) {
262             dest[0] = 255;
263             dest[1] = src[0]+PaethPredictor(lastr,old[1],upperlastr);
264             dest[2] = src[1]+PaethPredictor(lastg,old[2],upperlastg);
265             dest[3] = src[2]+PaethPredictor(lastb,old[3],upperlastb);
266             lastr = dest[1];
267             lastg = dest[2];
268             lastb = dest[3];
269             upperlastr = old[1];
270             upperlastg = old[2];
271             upperlastb = old[3];
272             dest+=4;
273             old+=4;
274             src+=3;
275         }
276     }    
277
278 }
279
280 void applyfilter4(int mode, U8*src, U8*old, U8*dest, int width)
281 {
282     int x;
283     unsigned char lastr=0;
284     unsigned char lastg=0;
285     unsigned char lastb=0;
286     unsigned char lasta=0;
287     unsigned char upperlastr=0;
288     unsigned char upperlastg=0;
289     unsigned char upperlastb=0;
290     unsigned char upperlasta=0;
291
292     if(mode==0) {
293         for(x=0;x<width;x++) {
294             dest[0] = src[3];
295             dest[1] = src[0];
296             dest[2] = src[1];
297             dest[3] = src[2];
298             dest+=4;
299             src+=4;
300         }
301     }
302     else if(mode==1) {
303         for(x=0;x<width;x++) {
304             dest[0] = src[3]+lasta;
305             dest[1] = src[0]+lastr;
306             dest[2] = src[1]+lastg;
307             dest[3] = src[2]+lastb;
308             lasta = dest[0];
309             lastr = dest[1];
310             lastg = dest[2];
311             lastb = dest[3];
312             dest+=4;
313             src+=4;
314         }
315     }
316     else if(mode==2) {
317         for(x=0;x<width;x++) {
318             dest[0] = src[3]+old[0];
319             dest[1] = src[0]+old[1];
320             dest[2] = src[1]+old[2];
321             dest[3] = src[2]+old[3];
322             dest+=4;
323             old+=4;
324             src+=4;
325         }
326     }
327     else if(mode==3) {
328         for(x=0;x<width;x++) {
329             dest[0] = src[3]+(old[0]+lasta)/2;
330             dest[1] = src[0]+(old[1]+lastr)/2;
331             dest[2] = src[1]+(old[2]+lastg)/2;
332             dest[3] = src[2]+(old[3]+lastb)/2;
333             lastr = dest[1];
334             lastg = dest[2];
335             lastb = dest[3];
336             dest+=4;
337             old+=4;
338             src+=4;
339         }
340     }
341     else if(mode==4) {
342         for(x=0;x<width;x++) {
343             dest[0] = src[3]+PaethPredictor(lasta,old[0],upperlasta);
344             dest[1] = src[0]+PaethPredictor(lastr,old[1],upperlastr);
345             dest[2] = src[1]+PaethPredictor(lastg,old[2],upperlastg);
346             dest[3] = src[2]+PaethPredictor(lastb,old[3],upperlastb);
347             lasta = dest[0];
348             lastr = dest[1];
349             lastg = dest[2];
350             lastb = dest[3];
351             upperlastr = old[0];
352             upperlastr = old[1];
353             upperlastg = old[2];
354             upperlastb = old[3];
355             dest+=4;
356             old+=4;
357             src+=4;
358         }
359     }    
360
361 }
362
363 void applyfilter1(int mode, U8*src, U8*old, U8*dest, int width)
364 {
365     int x;
366     unsigned char last=0;
367     unsigned char upperlast=0;
368
369     if(mode==0) {
370         for(x=0;x<width;x++) {
371             *dest = *src;
372             dest++;
373             src++;
374         }
375     }
376     else if(mode==1) {
377         for(x=0;x<width;x++) {
378             *dest = *src+last;
379             last = *dest;
380             dest++;
381             src++;
382         }
383     }
384     else if(mode==2) {
385         for(x=0;x<width;x++) {
386             *dest = *src+*old;
387             dest++;
388             old++;
389             src++;
390         }
391     }
392     else if(mode==3) {
393         for(x=0;x<width;x++) {
394             *dest = *src+(*old+last)/2;
395             dest++;
396             old++;
397             src++;
398         }
399     }
400     else if(mode==4) {
401         for(x=0;x<width;x++) {
402             *dest = *src+PaethPredictor(last,*old,upperlast);
403             last = *dest;
404             upperlast = *old;
405             dest++;
406             old++;
407             src++;
408         }
409     }    
410
411 }
412
413 TAG *MovieAddFrame(SWF * swf, TAG * t, char *sname, int id)
414 {
415     SHAPE *s;
416     SRECT r;
417     MATRIX m;
418     int fs;
419
420     char tagid[4];
421     int len;
422     U8*data;
423     U8*imagedata;
424     U8*zimagedata=0;
425     unsigned long int imagedatalen;
426     unsigned long int zimagedatalen=0;
427     U8*palette = 0;
428     int palettelen = 0;
429     U8*alphapalette = 0;
430     int alphapalettelen = 0;
431     struct png_header header;
432     int bypp;
433
434     FILE *fi;
435     U8 *scanline;
436
437     if ((fi = fopen(sname, "rb")) == NULL) {
438         if (VERBOSE(1))
439             fprintf(stderr, "Read access failed: %s\n", sname);
440         return t;
441     }
442
443     if(!png_read_header(fi, &header))
444         return 0;
445
446     if(header.mode == 3) bypp = 1;
447     else
448     if(header.mode == 2) bypp = 3;
449     else
450     if(header.mode == 6) bypp = 4;
451     else
452         return 0;
453     imagedatalen = bypp * header.width * header.height + 65536;
454     imagedata = malloc(imagedatalen);
455
456     fseek(fi,8,SEEK_SET);
457     while(!feof(fi))
458     {
459         if(!png_read_chunk(&tagid, &len, &data, fi))
460             break;
461         if(!strncmp(tagid, "IEND", 4)) {
462             break;
463         }
464         if(!strncmp(tagid, "PLTE", 4)) {
465             palette = data;
466             palettelen = len/3;
467             data = 0; //don't free data
468             if(VERBOSE(2))
469                 printf("%d colors in palette\n", palettelen);
470         }
471         if(!strncmp(tagid, "tRNS", 4)) {
472             if(header.mode == 3) {
473                 alphapalette = data;
474                 alphapalettelen = len;
475                 data = 0; //don't free data
476                 if(VERBOSE(2))
477                     printf("found %d alpha colors\n", alphapalettelen);
478             }
479         }
480         if(!strncmp(tagid, "IDAT", 4)) {
481             if(!zimagedata) {
482                 zimagedatalen = len;
483                 zimagedata = malloc(len);
484                 memcpy(zimagedata,data,len);
485             } else {
486                 zimagedata = realloc(zimagedata, zimagedatalen+len);
487                 memcpy(&zimagedata[zimagedatalen], data, len);
488                 zimagedatalen += len;
489             }
490         }
491         if(data)
492             free(data);
493     }
494     
495     if(!zimagedata || uncompress(imagedata, &imagedatalen, zimagedata, zimagedatalen) != Z_OK) {
496         fprintf(stderr, "Couldn't uncompress %s!\n", sname);
497         if(zimagedata)
498             free(zimagedata);
499         return 0;
500     }
501     free(zimagedata);
502
503     if(alphapalette)
504         t = swf_InsertTag(t, ST_DEFINEBITSLOSSLESS2);
505     else
506         t = swf_InsertTag(t, ST_DEFINEBITSLOSSLESS);
507
508     swf_SetU16(t, id);          // id
509     if(header.mode == 2 || header.mode == 6) {
510         U8*data2 = malloc(header.width*header.height*4);
511         int i,s=0;
512         int x,y;
513         int pos=0;
514         /* in case for mode 2, the following also performs 24->32 bit conversion */
515         for(y=0;y<header.height;y++) {
516             int mode = imagedata[pos++]; //filter mode
517             U8*src;
518             U8*dest;
519             U8*old;
520             dest = &data2[(y*header.width)*4];
521
522             if(header.bpp == 8)
523             {
524                 /* one byte per pixel */
525                 src = &imagedata[pos];
526                 pos+=header.width*(header.mode==6?4:3);
527             } else {
528                 /* not implemented yet */
529                 exit(1);
530             }
531
532             if(!y) {
533                 memset(data2,0,header.width*4);
534                 old = &data2[y*header.width*4];
535             } else {
536                 old = &data2[(y-1)*header.width*4];
537             }
538             if(header.mode==6)
539                 applyfilter4(mode, src, old, dest, header.width);
540             else
541                 applyfilter3(mode, src, old, dest, header.width);
542         }
543         swf_SetLosslessBits(t, header.width, header.height, data2, BMF_32BIT);
544         free(data2);
545     }
546     else {
547         RGBA*rgba = (RGBA*)malloc(palettelen*sizeof(RGBA));
548         int swf_width = BYTES_PER_SCANLINE(header.width);
549         U8*data2 = malloc(swf_width*header.height);
550         U8*tmpline = malloc(header.width);
551         int i,x,y;
552         int pos=0;
553         if(!palette) {
554             fprintf(stderr, "Error: No palette found!\n");
555             exit(1);
556         }
557         /* 24->32 bit conversion */
558         for(i=0;i<palettelen;i++) {
559             rgba[i].r = palette[i*3+0];
560             rgba[i].g = palette[i*3+1];
561             rgba[i].b = palette[i*3+2];
562             if(alphapalette && i<alphapalettelen) {
563                 rgba[i].a = alphapalette[i];
564                 if(alphapalette[i] == 0) {
565                     /* if the color is fully transparent, it doesn't matter
566                        what it's rgb values are. furthermore, all Flash 
567                        players up to Flash 5 can't deal with anything beyond
568                        one transparent color with value (00,00,00,00). */
569                     rgba[i].r = rgba[i].g = rgba[i].b = 0;
570                 }
571             } else {
572                 rgba[i].a = 255;
573             }
574         }
575
576         for(y=0;y<header.height;y++) {
577             int mode = imagedata[pos++]; //filter mode
578             U8*old;
579             U8*dest = &data2[y*swf_width];
580             U8*src;
581             src = &imagedata[pos];
582             if(header.bpp == 8) {
583                 pos+=header.width;
584             } else {
585                 int x,s=0;
586                 int bitpos = 0;
587                 U32 v = (1<<header.bpp)-1;
588                 for(x=0;x<header.width;x++) {
589                     U32 r = src[s/8]<<8 | 
590                             src[s/8+1];
591                     int t;
592                     tmpline[x] = (r>>(16-header.bpp-(s&7)))&v;
593                     s+=header.bpp;
594                 }
595                 src = tmpline;
596                 pos+=(header.width*header.bpp+7)/8;
597             }
598
599             if(!y) {
600                 memset(data2,0,swf_width);
601                 old = &data2[y*swf_width];
602             } else {
603                 old = &data2[(y-1)*swf_width];
604             }
605             applyfilter1(mode, src, old, dest, header.width);
606         }
607         swf_SetLosslessBitsIndexed(t, header.width, header.height, data2, rgba, palettelen);
608         free(tmpline);
609         free(rgba);
610         free(data2);
611     }
612
613     t = swf_InsertTag(t, ST_DEFINESHAPE);
614
615     swf_ShapeNew(&s);
616     swf_GetMatrix(NULL, &m);
617     m.sx = 20 * 0x10000;
618     m.sy = 20 * 0x10000;
619     fs = swf_ShapeAddBitmapFillStyle(s, &m, id, 0);
620
621     swf_SetU16(t, id + 1);      // id
622
623     r.xmin = r.ymin = 0;
624     r.xmax = header.width * 20;
625     r.ymax = header.height * 20;
626     swf_SetRect(t, &r);
627
628     swf_SetShapeHeader(t, s);
629
630     swf_ShapeSetAll(t, s, 0, 0, 0, fs, 0);
631     swf_ShapeSetLine(t, s, r.xmax, 0);
632     swf_ShapeSetLine(t, s, 0, r.ymax);
633     swf_ShapeSetLine(t, s, -r.xmax, 0);
634     swf_ShapeSetLine(t, s, 0, -r.ymax);
635
636     swf_ShapeSetEnd(t);
637
638     t = swf_InsertTag(t, ST_REMOVEOBJECT2);
639     swf_SetU16(t, 1);           // depth
640
641     t = swf_InsertTag(t, ST_PLACEOBJECT2);
642
643     swf_GetMatrix(NULL, &m);
644     m.tx = (swf->movieSize.xmax - (int) header.width * 20) / 2;
645     m.ty = (swf->movieSize.ymax - (int) header.height * 20) / 2;
646     swf_ObjectPlace(t, id + 1, 1, &m, NULL, NULL);
647
648     t = swf_InsertTag(t, ST_SHOWFRAME);
649
650     fclose(fi);
651
652     return t;
653 }
654
655
656 int CheckInputFile(char *fname, char **realname)
657 {
658     FILE *fi;
659     char *s = malloc(strlen(fname) + 5);
660     struct png_header head;
661
662     if (!s)
663         exit(2);
664     (*realname) = s;
665     strcpy(s, fname);
666
667     // Check whether file exists (with typical extensions)
668
669     if ((fi = fopen(s, "rb")) == NULL) {
670         sprintf(s, "%s.png", fname);
671         if ((fi = fopen(s, "rb")) == NULL) {
672             sprintf(s, "%s.PNG", fname);
673             if ((fi = fopen(s, "rb")) == NULL) {
674                 sprintf(s, "%s.Png", fname);
675                 if ((fi = fopen(s, "rb")) == NULL)
676                     fprintf(stderr, "Couldn't open %s!\n", fname);
677                     return -1;
678             }
679         }
680     }
681
682     if(!png_read_header(fi, &head)) {
683         fprintf(stderr, "%s is not a PNG file!\n", fname);
684         return -1;
685     }
686
687     if (global.max_image_width < head.width)
688         global.max_image_width = head.width;
689     if (global.max_image_height < head.height)
690         global.max_image_height = head.height;
691
692     fclose(fi);
693
694     return 0;
695 }
696
697 int args_callback_option(char *arg, char *val)
698 {
699     int res = 0;
700     if (arg[1])
701         res = -1;
702     else
703         switch (arg[0]) {
704         case 'r':
705             if (val)
706                 global.framerate = atoi(val);
707             if ((global.framerate < 1) ||(global.framerate > 5000)) {
708                 if (VERBOSE(1))
709                     fprintf(stderr,
710                             "Error: You must specify a valid framerate between 1 and 10000.\n");
711                 exit(1);
712             }
713             res = 1;
714             break;
715
716         case 'o':
717             if (val)
718                 global.outfile = val;
719             res = 1;
720             break;
721
722         case 'v':
723             if (val)
724                 global.verbose = atoi(val);
725             res = 1;
726             break;
727
728         case 'X':
729             if (val)
730                 global.force_width = atoi(val);
731             res = 1;
732             break;
733
734         case 'Y':
735             if (val)
736                 global.force_height = atoi(val);
737             res = 1;
738             break;
739
740         case 'V':
741             printf("png2swf - part of %s %s\n", PACKAGE, VERSION);
742             exit(0);
743
744         default:
745             res = -1;
746             break;
747         }
748
749     if (res < 0) {
750         if (VERBOSE(1))
751             fprintf(stderr, "Unknown option: -%s\n", arg);
752         exit(1);
753         return 0;
754     }
755     return res;
756 }
757
758 struct options_t options[] = 
759
760 {"o", "output"},
761 {"r", "rate"},
762 {"v", "verbose"},
763 {"X", "width"},
764 {"Y", "height"},
765 {"V", "version"},
766 };
767
768 int args_callback_longoption(char *name, char *val)
769 {
770     return args_long2shortoption(options, name, val);
771 }
772
773 int args_callback_command(char *arg, char *next)        // actually used as filename
774 {
775     char *s;
776     if (CheckInputFile(arg, &s) < 0) {
777         if (VERBOSE(1))
778             fprintf(stderr, "Error opening input file: %s\n", arg);
779         free(s);
780     } else {
781         image[global.nfiles].filename = s;
782         global.nfiles++;
783         if (global.nfiles >= MAX_INPUT_FILES) {
784             if (VERBOSE(1))
785                 fprintf(stderr, "Error: Too many input files.\n");
786             exit(1);
787         }
788     }
789     return 0;
790 }
791
792 void args_callback_usage(char *name)
793 {
794     printf("Usage: %s  [-options [value]] imagefiles[.png] [...]\n", name);
795     printf("-r framerate          (rate) Set movie framerate (100/sec)\n");
796     printf("-o outputfile         (output) Set name for SWF output file\n");
797     printf("-X pixel              (width) Force movie width to pixel (default: autodetect)\n");
798     printf("-Y pixel              (height) Force movie height to pixel (default: autodetect)\n");
799     printf("-v level              (verbose) Set verbose level (0=quiet, 1=default, 2=debug)\n");
800     printf("-V                    (version) Print version information and exit\n");
801 }
802
803
804 int main(int argc, char **argv)
805 {
806     SWF swf;
807     TAG *t;
808
809     memset(&global, 0x00, sizeof(global));
810
811     global.framerate = 100;
812     global.verbose = 1;
813
814     processargs(argc, argv);
815
816     if(global.nfiles<=0)
817         return 1;
818
819     if (VERBOSE(2))
820         fprintf(stderr, "Processing %i file(s)...\n", global.nfiles);
821
822     t = MovieStart(&swf, global.framerate,
823                    global.force_width ? global.force_width : global.
824                    max_image_width,
825                    global.force_height ? global.force_height : global.
826                    max_image_height);
827
828     {
829         int i;
830         for (i = 0; i < global.nfiles; i++) {
831             if (VERBOSE(3))
832                 fprintf(stderr, "[%03i] %s\n", i,
833                         image[i].filename);
834             t = MovieAddFrame(&swf, t, image[i].filename, (i * 2) + 1);
835             free(image[i].filename);
836         }
837     }
838
839     MovieFinish(&swf, t, global.outfile);
840
841     return 0;
842 }