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"
13 #include "../lib/devices/rescale.h"
15 static struct options_t options[] = {
27 static char*filename = 0;
28 static char*outputname = "output.png";
29 static int quantize = 0;
30 static char*pagerange = 0;
33 static int height = 0;
35 typedef struct _parameter {
38 struct _parameter*next;
41 parameter_t*params = 0;
43 int args_callback_option(char*name,char*val)
45 if(!strcmp(name, "V")) {
46 printf("swfrender - part of %s %s\n", PACKAGE, VERSION);
48 } else if(!strcmp(name, "o")) {
49 outputname = strdup(val);
51 } else if(!strcmp(name, "l")) {
54 } else if(!strcmp(name, "q")) {
57 } else if(!strcmp(name, "p")) {
60 } else if(!strcmp(name, "s")) {
62 char*c = strchr(s, '=');
63 parameter_t*p = malloc(sizeof(parameter_t));
76 } else if(!strcmp(name, "X")) {
79 } else if(!strcmp(name, "Y")) {
83 printf("Unknown option: -%s\n", name);
89 int args_callback_longoption(char*name,char*val)
91 return args_long2shortoption(options, name, val);
93 void args_callback_usage(char *name)
96 printf("Usage: %s file.swf [-o output.png]\n", name);
98 printf("-h , --help Print short help message and exit\n");
99 printf("-l , --legacy Use old rendering framework\n");
100 printf("-o , --output Output file (default: output.png)\n");
103 int args_callback_command(char*name,char*val)
106 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
115 int main(int argn, char*argv[])
120 processargs(argn, argv);
123 fprintf(stderr, "You must supply a filename.\n");
128 fi = open(filename, O_RDONLY|O_BINARY);
130 fprintf(stderr,"Couldn't open %s\n", filename);
134 if(swf_ReadSWF(fi,&swf)<0) {
135 fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
138 assert(swf.movieSize.xmax > swf.movieSize.xmin && swf.movieSize.ymax > swf.movieSize.ymin);
140 swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20,
141 (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1);
142 swf_RenderSWF(&buf, &swf);
143 RGBA* img = swf_Render(&buf);
145 writePalettePNG(outputname, (unsigned char*)img, buf.width, buf.height);
147 writePNG(outputname, (unsigned char*)img, buf.width, buf.height);
148 swf_Render_Delete(&buf);
152 gfxsource_t*src = gfxsource_swf_create();
153 for(p=params;p;p=p->next) {
154 src->setparameter(src, p->name, p->value);
156 gfxdocument_t*doc = src->open(src, filename);
157 for(p=params;p;p=p->next) {
158 doc->setparameter(doc, p->name, p->value);
161 fprintf(stderr,"Couldn't open %s\n", filename);
164 gfxdevice_t dev2,*dev=&dev2;
165 gfxdevice_render_init(dev);
166 dev->setparameter(dev, "antialise", "4");
168 dev->setparameter(dev, "palette", "1");
170 if(width || height) {
171 dev = gfxdevice_rescale_new(dev, width, height, 0);
173 for(p=params;p;p=p->next) {
174 dev->setparameter(dev, p->name, p->value);
178 for(t=1;t<=doc->num_pages;t++) {
179 if(!is_in_range(t, pagerange))
181 gfxpage_t* page = doc->getpage(doc, t);
182 dev->startpage(dev, page->width, page->height);
183 page->render(page, dev);
188 gfxresult_t*result = dev->finish(dev);
190 if(result->save(result, outputname) < 0) {
193 result->destroy(result);