diff --git a/LICENSE.txt b/LICENSE.txt index 2a03a1a..6fde401 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2013 Mikko Mononen memon@inside.org +Copyright (c) 2013-14 Mikko Mononen memon@inside.org This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/README.md b/README.md index 6151c37..e68c5a9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ Nano SVG ========== -![screenshot of some splines rendered witht the sample program](/example/screenshot.png?raw=true) +## Parser + +![screenshot of some splines rendered witht the sample program](/example/screenshot-1.png?raw=true) NanoSVG is a simple stupid single-header-file SVG parse. The output of the parser is a list of cubic bezier shapes. @@ -9,12 +11,20 @@ The library suits well for anything from rendering scalable icons in your editor NanoSVG supports a wide range of SVG features, if somehing is missing, feel free to create a pull request! +## Rasterizer + +![screenshot of tiger.svg rendered with NanoSVG rasterizer](/example/screenshot-2.png?raw=true) + +The parser library is accompanied with really simpler SVG rasterizer. Currently it only renders flat filled shapes. + +The intended usage for the rasterizer is to for example bake icons of different size into a texture. The rasterizer is not particular fast or accurate, but it's small and packed in one header file. + ## Example Usage ``` C // Load -struct SNVGImage* image; +struct NSVGimage* image; image = nsvgParseFromFile("test.svg."); printf("size: %f x %f\n", image->width, image->height); // Use... diff --git a/example/screenshot.png b/example/screenshot-1.png similarity index 100% rename from example/screenshot.png rename to example/screenshot-1.png diff --git a/example/screenshot-2.png b/example/screenshot-2.png new file mode 100644 index 0000000..a4641f8 Binary files /dev/null and b/example/screenshot-2.png differ diff --git a/src/nanosvg.h b/src/nanosvg.h index 4726f55..098e5b2 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Mikko Mononen memon@inside.org + * Copyright (c) 2013-14 Mikko Mononen memon@inside.org * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/src/nanosvgrast.h b/src/nanosvgrast.h index bee08f1..b0e3aec 100644 --- a/src/nanosvgrast.h +++ b/src/nanosvgrast.h @@ -1,3 +1,27 @@ +/* + * Copyright (c) 2013-14 Mikko Mononen memon@inside.org + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + * + * The polygon rasterization is heavily based on stb_truetype rasterizer + * by Sean Barrett - http://nothings.org/ + * + */ + #ifndef NANOSVGRAST_H #define NANOSVGRAST_H @@ -5,13 +29,35 @@ extern "C" { #endif +/* Example Usage: + // Load SVG + struct SNVGImage* image = nsvgParseFromFile("test.svg."); + // Create rasterizer (can be used to render multiple images). + struct NSVGrasterizer* rast = nsvgCreateRasterizer(); + // Allocate memory for image + unsigned char* img = malloc(w*h*4); + // Rasterize + nsvgRasterize(rast, image, 0,0,1, img, w, h, w*4); +*/ + +// Allocated rasterizer context. struct NSVGrasterizer* nsvgCreateRasterizer(); +// Rasterizes SVG image, returns RGBA image (non-premultiplied alpha) +// r - pointer to rasterizer context +// image - pointer to image to rasterize +// tx,ty - image offset (applied after scaling) +// scale - image scale +// dst - pointer to destination image data, 4 bytes per pixel (RGBA) +// w - width of the image to render +// h - height of the image to render +// stride - number of bytes per scaleline in the destination buffer void nsvgRasterize(struct NSVGrasterizer* r, struct NSVGimage* image, float tx, float ty, float scale, unsigned char* dst, int w, int h, int stride); +// Deletes rasterizer context. void nsvgDeleteRasterizer(struct NSVGrasterizer*); @@ -25,8 +71,6 @@ void nsvgDeleteRasterizer(struct NSVGrasterizer*); #include -// The polygon rasterization is heavily based on stb_truetype rasterizer by Sean Barrett - http://nothings.org/ - #define NSVG__SUBSAMPLES 5 #define NSVG__FIXSHIFT 10 #define NSVG__FIX (1 << NSVG__FIXSHIFT)