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[] = {
25 static char*filename = 0;
26 static char*outputname = "output.png";
27 static int quantize = 0;
30 static int height = 0;
32 int args_callback_option(char*name,char*val)
34 if(!strcmp(name, "V")) {
35 printf("swfrender - part of %s %s\n", PACKAGE, VERSION);
37 } else if(!strcmp(name, "o")) {
38 outputname = strdup(val);
40 } else if(!strcmp(name, "l")) {
43 } else if(!strcmp(name, "q")) {
46 } else if(!strcmp(name, "X")) {
49 } else if(!strcmp(name, "Y")) {
53 printf("Unknown option: -%s\n", name);
59 int args_callback_longoption(char*name,char*val)
61 return args_long2shortoption(options, name, val);
63 void args_callback_usage(char *name)
66 printf("Usage: %s file.swf [-o output.png]\n", name);
68 printf("-h , --help Print short help message and exit\n");
69 printf("-l , --legacy Use old rendering framework\n");
70 printf("-o , --output Output file (default: output.png)\n");
73 int args_callback_command(char*name,char*val)
76 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
85 int main(int argn, char*argv[])
90 processargs(argn, argv);
93 fprintf(stderr, "You must supply a filename.\n");
98 fi = open(filename, O_RDONLY|O_BINARY);
100 fprintf(stderr,"Couldn't open %s\n", filename);
104 if(swf_ReadSWF(fi,&swf)<0) {
105 fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
109 swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20,
110 (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1);
111 swf_RenderSWF(&buf, &swf);
112 RGBA* img = swf_Render(&buf);
114 writePalettePNG(outputname, (unsigned char*)img, buf.width, buf.height);
116 writePNG(outputname, (unsigned char*)img, buf.width, buf.height);
117 swf_Render_Delete(&buf);
119 gfxsource_t*src = gfxsource_swf_create();
120 gfxdocument_t*doc = src->open(src, filename);
122 fprintf(stderr,"Couldn't open %s\n", filename);
125 gfxdevice_t dev2,*dev=&dev2;
126 gfxdevice_render_init(dev);
128 dev->setparameter(dev, "palette", "1");
130 if(width || height) {
131 dev = gfxdevice_rescale_new(dev, width, height, 0);
135 for(t=1;t<=doc->num_pages;t++) {
136 gfxpage_t* page = doc->getpage(doc, t);
137 dev->startpage(dev, page->width, page->height);
138 page->render(page, dev);
143 gfxresult_t*result = dev->finish(dev);
145 if(result->save(result, outputname) < 0) {
148 result->destroy(result);