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[] = {
26 static char*filename = 0;
27 static char*outputname = "output.png";
28 static int quantize = 0;
31 static int height = 0;
33 typedef struct _parameter {
36 struct _parameter*next;
39 parameter_t*params = 0;
41 int args_callback_option(char*name,char*val)
43 if(!strcmp(name, "V")) {
44 printf("swfrender - part of %s %s\n", PACKAGE, VERSION);
46 } else if(!strcmp(name, "o")) {
47 outputname = strdup(val);
49 } else if(!strcmp(name, "l")) {
52 } else if(!strcmp(name, "q")) {
55 } else if(!strcmp(name, "s")) {
57 char*c = strchr(s, '=');
58 parameter_t*p = malloc(sizeof(parameter_t));
71 } else if(!strcmp(name, "X")) {
74 } else if(!strcmp(name, "Y")) {
78 printf("Unknown option: -%s\n", name);
84 int args_callback_longoption(char*name,char*val)
86 return args_long2shortoption(options, name, val);
88 void args_callback_usage(char *name)
91 printf("Usage: %s file.swf [-o output.png]\n", name);
93 printf("-h , --help Print short help message and exit\n");
94 printf("-l , --legacy Use old rendering framework\n");
95 printf("-o , --output Output file (default: output.png)\n");
98 int args_callback_command(char*name,char*val)
101 fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
110 int main(int argn, char*argv[])
115 processargs(argn, argv);
118 fprintf(stderr, "You must supply a filename.\n");
123 fi = open(filename, O_RDONLY|O_BINARY);
125 fprintf(stderr,"Couldn't open %s\n", filename);
129 if(swf_ReadSWF(fi,&swf)<0) {
130 fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]);
134 swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20,
135 (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1);
136 swf_RenderSWF(&buf, &swf);
137 RGBA* img = swf_Render(&buf);
139 writePalettePNG(outputname, (unsigned char*)img, buf.width, buf.height);
141 writePNG(outputname, (unsigned char*)img, buf.width, buf.height);
142 swf_Render_Delete(&buf);
146 gfxsource_t*src = gfxsource_swf_create();
147 for(p=params;p;p=p->next) {
148 src->set_parameter(src, p->name, p->value);
150 gfxdocument_t*doc = src->open(src, filename);
151 for(p=params;p;p=p->next) {
152 doc->set_parameter(doc, p->name, p->value);
155 fprintf(stderr,"Couldn't open %s\n", filename);
158 gfxdevice_t dev2,*dev=&dev2;
159 gfxdevice_render_init(dev);
160 dev->setparameter(dev, "antialise", "4");
162 dev->setparameter(dev, "palette", "1");
164 if(width || height) {
165 dev = gfxdevice_rescale_new(dev, width, height, 0);
167 for(p=params;p;p=p->next) {
168 dev->setparameter(dev, p->name, p->value);
172 for(t=1;t<=doc->num_pages;t++) {
173 gfxpage_t* page = doc->getpage(doc, t);
174 dev->startpage(dev, page->width, page->height);
175 page->render(page, dev);
180 gfxresult_t*result = dev->finish(dev);
182 if(result->save(result, outputname) < 0) {
185 result->destroy(result);