diff --git a/example/example2.c b/example/nanosvg.c similarity index 57% rename from example/example2.c rename to example/nanosvg.c index 9ae9b595..b15147fd 100644 --- a/example/example2.c +++ b/example/nanosvg.c @@ -26,44 +26,48 @@ #define NANOSVGRAST_IMPLEMENTATION #include "nanosvgrast.h" -int main() +int main(int argc, char * argv[]) { NSVGimage *image = NULL; NSVGrasterizer *rast = NULL; unsigned char* img = NULL; int w, h; - const char* filename = "../example/23.svg"; + const char* filename; + char outfile[4096]; - printf("parsing %s\n", filename); - image = nsvgParseFromFile(filename, "px", 96.0f); - if (image == NULL) { - printf("Could not open SVG image.\n"); - goto error; - } - w = (int)image->width; - h = (int)image->height; + for (int argi = 1; argi < argc; argi++) { + filename = argv[argi]; + printf("parsing %s\n", filename); + image = nsvgParseFromFile(filename, "px", 96.0f); + if (image == NULL) { + printf("Could not open SVG image.\n"); + goto error; + } + w = (int)image->width; + h = (int)image->height; - rast = nsvgCreateRasterizer(); - if (rast == NULL) { - printf("Could not init rasterizer.\n"); - goto error; - } + rast = nsvgCreateRasterizer(); + if (rast == NULL) { + printf("Could not init rasterizer for '%s'.\n", filename); + goto error; + } - img = malloc(w*h*4); - if (img == NULL) { - printf("Could not alloc image buffer.\n"); - goto error; - } + img = malloc(w*h*4); + if (img == NULL) { + printf("Could not alloc image buffer for '%s'.\n", filename); + goto error; + } - printf("rasterizing image %d x %d\n", w, h); - nsvgRasterize(rast, image, 0,0,1, img, w, h, w*4); + printf("rasterizing image %d x %d\n", w, h); + nsvgRasterize(rast, image, 0,0,1, img, w, h, w*4); + snprintf(outfile, sizeof(outfile), "%s.png", filename); + printf("writing %s\n", outfile); + stbi_write_png(outfile, w, h, 4, img, w*4); - printf("writing svg.png\n"); - stbi_write_png("svg.png", w, h, 4, img, w*4); - -error: - nsvgDeleteRasterizer(rast); - nsvgDelete(image); + error: + nsvgDeleteRasterizer(rast); + nsvgDelete(image); + } return 0; } diff --git a/premake4.lua b/premake4.lua index 8befd82e..b48dde71 100644 --- a/premake4.lua +++ b/premake4.lua @@ -31,10 +31,10 @@ solution "nanosvg" defines { "NDEBUG" } flags { "Optimize", "ExtraWarnings"} - project "example2" + project "nanosvg" kind "ConsoleApp" language "C++" - files { "example/example2.c", "example/*.h", "src/*.h" } + files { "example/nanosvg.c", "example/*.h", "src/*.h" } includedirs { "example", "src" } targetdir("build")