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]);
139 swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20,
140 (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1);
141 swf_RenderSWF(&buf, &swf);
142 RGBA* img = swf_Render(&buf);
144 writePalettePNG(outputname, (unsigned char*)img, buf.width, buf.height);
146 writePNG(outputname, (unsigned char*)img, buf.width, buf.height);
147 swf_Render_Delete(&buf);
151 gfxsource_t*src = gfxsource_swf_create();
152 for(p=params;p;p=p->next) {
153 src->set_parameter(src, p->name, p->value);
155 gfxdocument_t*doc = src->open(src, filename);
156 for(p=params;p;p=p->next) {
157 doc->set_parameter(doc, p->name, p->value);
160 fprintf(stderr,"Couldn't open %s\n", filename);
163 gfxdevice_t dev2,*dev=&dev2;
164 gfxdevice_render_init(dev);
165 dev->setparameter(dev, "antialise", "4");
167 dev->setparameter(dev, "palette", "1");
169 if(width || height) {
170 dev = gfxdevice_rescale_new(dev, width, height, 0);
172 for(p=params;p;p=p->next) {
173 dev->setparameter(dev, p->name, p->value);
177 for(t=1;t<=doc->num_pages;t++) {
178 if(!is_in_range(t, pagerange))
180 gfxpage_t* page = doc->getpage(doc, t);
181 dev->startpage(dev, page->width, page->height);
182 page->render(page, dev);
187 gfxresult_t*result = dev->finish(dev);
189 if(result->save(result, outputname) < 0) {
192 result->destroy(result);