7 #include "../lib/rfxswf.h"
8 #include "../lib/png.h"
9 #include "../lib/args.h"
10 #include "../lib/gfxsource.h"
11 #include "../lib/readers/swf.h"
12 #include "../lib/devices/render.h"
14 static struct options_t options[] = {
23 static char*filename = 0;
24 static char*outputname = "output.png";
26 int args_callback_option(char*name,char*val)
28 if(!strcmp(name, "V")) {
29 printf("swfrender - part of %s %s\n", PACKAGE, VERSION);
31 } else if(!strcmp(name, "o")) {
32 outputname = strdup(val);
34 } else if(!strcmp(name, "n")) {
38 printf("Unknown option: -%s\n", name);
44 int args_callback_longoption(char*name,char*val)
46 return args_long2shortoption(options, name, val);
48 void args_callback_usage(char *name)
51 printf("Usage: %s file.swf [-o output.png]\n", name);
53 printf("-h , --help Print short help message and exit\n");
54 printf("-n , --ng Use next generation renderer (based on gfxdevice)\n");
55 printf("-o , --output Output file (default: output.png)\n");
58 int args_callback_command(char*name,char*val)
61 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
70 int main(int argn, char*argv[])
75 processargs(argn, argv);
78 fprintf(stderr, "You must supply a filename.\n");
83 fi = open(filename, O_RDONLY|O_BINARY);
85 fprintf(stderr,"Couldn't open %s\n", filename);
89 if(swf_ReadSWF(fi,&swf)<0) {
90 fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
94 swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20,
95 (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1);
96 swf_RenderSWF(&buf, &swf);
97 RGBA* img = swf_Render(&buf);
98 writePNG(outputname, (unsigned char*)img, buf.width, buf.height);
99 swf_Render_Delete(&buf);
101 gfxsource_t*src = gfxsource_swf_create();
102 gfxdocument_t*doc = src->open(src, filename);
104 fprintf(stderr,"Couldn't open %s\n", filename);
107 gfxdevice_t dev2,*dev=&dev2;
108 gfxdevice_render_init(dev);
111 for(t=1;t<=doc->num_pages;t++) {
112 gfxpage_t* page = doc->getpage(doc, t);
113 dev->startpage(dev, page->width, page->height);
114 page->render(page, dev);
119 gfxresult_t*result = dev->finish(dev);
121 if(result->save(result, outputname) < 0) {
124 result->destroy(result);