egra: agg mini clipping bugfix; some fixes in widget rendering (buttons, etc.)
[iv.d.git] / nanovega_demo / svgraster.d
blobce209a72cd1339a84bcb7afffb0d015b308cbad8
1 //
2 // Copyright (c) 2013 Mikko Mononen memon@inside.org
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // 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 it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
18 import core.stdc.stdio;
19 import iv.nanovega.svg;
21 import arsd.color;
22 import arsd.image;
25 void writePng (NSVG* svg, string ofname) {
26 import core.time, std.datetime;
27 import std.stdio : writeln;
28 assert(svg !is null);
29 assert(cast(int)svg.width > 0);
30 assert(cast(int)svg.height > 0);
31 assert(svg.width < 32768);
32 assert(svg.height < 32768);
34 ubyte[] svgraster;
35 auto rst = nsvgCreateRasterizer();
36 scope(exit) rst.kill();
37 auto stt = MonoTime.currTime;
38 svgraster = new ubyte[](cast(int)svg.width*cast(int)svg.height*4);
39 rst.rasterize(svg,
40 0, 0, // ofs
41 1, // scale
42 svgraster.ptr, cast(int)svg.width, cast(int)svg.height);
43 auto dur = (MonoTime.currTime-stt).total!"msecs";
44 writeln("rasterizing took ", dur, " milliseconds (", dur/1000.0, " seconds)");
45 auto tc = new TrueColorImage(cast(int)svg.width, cast(int)svg.height, svgraster);
46 scope(exit) tc.destroy;
47 arsd.png.writePng(ofname, tc);
51 void main (string[] args) {
52 import core.time;
54 NSVG* svg;
55 scope(exit) svg.kill();
57 import std.stdio : writeln;
58 import core.time, std.datetime;
59 auto stt = MonoTime.currTime;
60 svg = nsvgParseFromFile(args.length > 1 ? args[1] : "data/svg/tiger.svg");
61 auto dur = (MonoTime.currTime-stt).total!"msecs";
62 writeln("loading took ", dur, " milliseconds (", dur/1000.0, " seconds)");
63 { import std.stdio; writeln(args.length > 1 ? args[1] : "data/svg/tiger.svg"); }
66 svg.writePng("zout.png");