Skip to content
Myr

example2.c

This file

Path

3rd-party/nanosvg/example/example2.c

69 lines · 1.9 KiB · C

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 6a4c416 point at it.

changelog: add missing refDaniel Eklöfbefore adoption6a4c416

lines 1–69why, one step back
1//
2// Copyright (c) 2013 Mikko Mononen memon@inside.org3//4// This software is provided 'as-is', without any express or implied5// warranty. In no event will the authors be held liable for any damages6// arising from the use of this software.7// Permission is granted to anyone to use this software for any purpose,8// including commercial applications, and to alter it and redistribute it9// freely, subject to the following restrictions:10// 1. The origin of this software must not be misrepresented; you must not11// claim that you wrote the original software. If you use this software12// in a product, an acknowledgment in the product documentation would be13// appreciated but is not required.14// 2. Altered source versions must be plainly marked as such, and must not be15// misrepresented as being the original software.16// 3. This notice may not be removed or altered from any source distribution.17//1819#include <stdio.h>20#include <string.h>21#include <float.h>22#define STB_IMAGE_WRITE_IMPLEMENTATION23#include "stb_image_write.h"24#define NANOSVG_IMPLEMENTATION25#include "nanosvg.h"26#define NANOSVGRAST_IMPLEMENTATION27#include "nanosvgrast.h"2829int main()30{31 NSVGimage *image = NULL;32 NSVGrasterizer *rast = NULL;33 unsigned char* img = NULL;34 int w, h;35 const char* filename = "../example/23.svg";3637 printf("parsing %s\n", filename);38 image = nsvgParseFromFile(filename, "px", 96.0f);39 if (image == NULL) {40 printf("Could not open SVG image.\n");41 goto error;42 }43 w = (int)image->width;44 h = (int)image->height;4546 rast = nsvgCreateRasterizer();47 if (rast == NULL) {48 printf("Could not init rasterizer.\n");49 goto error;50 }5152 img = malloc(w*h*4);53 if (img == NULL) {54 printf("Could not alloc image buffer.\n");55 goto error;56 }5758 printf("rasterizing image %d x %d\n", w, h);59 nsvgRasterize(rast, image, 0,0,1, img, w, h, w*4);6061 printf("writing svg.png\n");62 stbi_write_png("svg.png", w, h, 4, img, w*4);6364error:65 nsvgDeleteRasterizer(rast);66 nsvgDelete(image);6768 return 0;69}