From 2e9735ce690edb9a2fbce93d58cbe202a4eed068 Mon Sep 17 00:00:00 2001 From: kramm Date: Tue, 20 Feb 2007 18:52:35 +0000 Subject: [PATCH] new option --ng --- src/swfrender.c | 79 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/src/swfrender.c b/src/swfrender.c index bb106f4..24df1c5 100644 --- a/src/swfrender.c +++ b/src/swfrender.c @@ -7,14 +7,18 @@ #include "../lib/rfxswf.h" #include "../lib/png.h" #include "../lib/args.h" +#include "../lib/gfxsource.h" +#include "../lib/swf/swf.h" static struct options_t options[] = { {"h", "help"}, {"o", "output"}, +{"n", "ng"}, {"V", "version"}, {0,0} }; +static int ng = 0; static char*filename = 0; static char*outputname = "output.png"; @@ -26,6 +30,9 @@ int args_callback_option(char*name,char*val) } else if(!strcmp(name, "o")) { outputname = strdup(val); return 1; + } else if(!strcmp(name, "n")) { + ng = 1; + return 0; } else { printf("Unknown option: -%s\n", name); exit(1); @@ -43,6 +50,7 @@ void args_callback_usage(char *name) printf("Usage: %s file.swf [-o output.png]\n", name); printf("\n"); printf("-h , --help Print short help message and exit\n"); + printf("-n , --ng Use next generation renderer (based on gfxdevice)\n"); printf("-o , --output Output file (default: output.png)\n"); printf("\n"); } @@ -66,33 +74,56 @@ int main(int argn, char*argv[]) processargs(argn, argv); if(!filename) { - fprintf(stderr, "You must supply a filename.\n"); - return 1; - } - - fi = open(filename, O_RDONLY|O_BINARY); - if (fi<=0) { - fprintf(stderr,"Couldn't open %s\n", filename); - perror(argv[1]); - exit(1); + fprintf(stderr, "You must supply a filename.\n"); + return 1; } - if(swf_ReadSWF(fi,&swf)<0) { - fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]); - close(fi); + if(!ng) { + fi = open(filename, O_RDONLY|O_BINARY); + if (fi<=0) { + fprintf(stderr,"Couldn't open %s\n", filename); + perror(argv[1]); + exit(1); + } + if(swf_ReadSWF(fi,&swf)<0) { + fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",argv[1]); + close(fi); + } + RENDERBUF buf; + swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20, + (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1); + swf_RenderSWF(&buf, &swf); + RGBA* img = swf_Render(&buf); + writePNG(outputname, (unsigned char*)img, buf.width, buf.height); + swf_Render_Delete(&buf); + } else { + gfxsource_t*src = gfxsource_swf_create(); + gfxdocument_t*doc = src->open(filename); + if(!doc) { + fprintf(stderr,"Couldn't open %s\n", filename); + exit(1); + } + gfxdevice_t dev2,*dev=&dev2; + gfxdevice_render_init(dev); + + int t; + for(t=1;t<=doc->num_pages;t++) { + gfxpage_t* page = doc->getpage(doc, t); + dev->startpage(dev, page->width, page->height); + page->render(page, dev); + dev->endpage(dev); + page->destroy(page); + break; + } + gfxresult_t*result = dev->finish(dev); + if(result) { + if(result->save(result, outputname) < 0) { + exit(1); + } + result->destroy(result); + } + doc->destroy(doc); } - - RENDERBUF buf; - swf_Render_Init(&buf, 0,0, (swf.movieSize.xmax - swf.movieSize.xmin) / 20, - (swf.movieSize.ymax - swf.movieSize.ymin) / 20, 2, 1); - - swf_RenderSWF(&buf, &swf); - - RGBA* img = swf_Render(&buf); - - writePNG(outputname, (unsigned char*)img, buf.width, buf.height); - - swf_Render_Delete(&buf); return 0; } -- 1.7.10.4