7 #include "../lib/rfxswf.h"
8 #include "../lib/png.h"
9 #include "../lib/args.h"
10 #include "../lib/gfxsource.h"
11 #include "../lib/swf/swf.h"
13 static struct options_t options[] = {
22 static char*filename = 0;
23 static char*outputname = "output.png";
25 int args_callback_option(char*name,char*val)
27 if(!strcmp(name, "V")) {
28 printf("swfrender - part of %s %s\n", PACKAGE, VERSION);
30 } else if(!strcmp(name, "o")) {
31 outputname = strdup(val);
33 } else if(!strcmp(name, "n")) {
37 printf("Unknown option: -%s\n", name);
43 int args_callback_longoption(char*name,char*val)
45 return args_long2shortoption(options, name, val);
47 void args_callback_usage(char *name)
50 printf("Usage: %s file.swf [-o output.png]\n", name);
52 printf("-h , --help Print short help message and exit\n");
53 printf("-n , --ng Use next generation renderer (based on gfxdevice)\n");
54 printf("-o , --output Output file (default: output.png)\n");
57 int args_callback_command(char*name,char*val)
60 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
69 int main(int argn, char*argv[])
74 processargs(argn, argv);
77 fprintf(stderr, "You must supply a filename.\n");
82 fi = open(filename, O_RDONLY|O_BINARY);
84 fprintf(stderr,"Couldn't open %s\n", filename);
88 if(swf_ReadSWF(fi,&swf)<0) {
89 fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
93 swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20,
94 (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1);
95 swf_RenderSWF(&buf, &swf);
96 RGBA* img = swf_Render(&buf);
97 writePNG(outputname, (unsigned char*)img, buf.width, buf.height);
98 swf_Render_Delete(&buf);
100 gfxsource_t*src = gfxsource_swf_create();
101 gfxdocument_t*doc = src->open(filename);
103 fprintf(stderr,"Couldn't open %s\n", filename);
106 gfxdevice_t dev2,*dev=&dev2;
107 gfxdevice_render_init(dev);
110 for(t=1;t<=doc->num_pages;t++) {
111 gfxpage_t* page = doc->getpage(doc, t);
112 dev->startpage(dev, page->width, page->height);
113 page->render(page, dev);
118 gfxresult_t*result = dev->finish(dev);
120 if(result->save(result, outputname) < 0) {
123 result->destroy(result);