Updated documentation

master
Mikko Mononen 2014-01-09 23:22:38 +02:00
parent 8e47686015
commit b3f906a393
6 changed files with 60 additions and 6 deletions

View File

@ -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

View File

@ -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...

View File

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

BIN
example/screenshot-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

View File

@ -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

View File

@ -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 <math.h>
// 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)