sf-svg
SFC
nanosvg++
nanosvgrastr.hpp
Go to the documentation of this file.
1
/* ================================================ *
2
* nanosvg++ *
3
* This software is a fork of nanosvg (note below). *
4
* No license-related aspects are affected. *
5
* Kamil Koczurek | koczurekk@gmail.com *
6
* ================================================ */
7
/* ============================================================================ *
8
* Copyright (c) 2013-14 Mikko Mononen memon@inside.org *
9
* *
10
* This software is provided 'as-is', without any express or implied *
11
* warranty. In no event will the authors be held liable for any damages *
12
* arising from the use of this software. *
13
* *
14
* Permission is granted to anyone to use this software for any purpose, *
15
* including commercial applications, and to alter it and redistribute it *
16
* freely, subject to the following restrictions: *
17
* *
18
* 1. The origin of this software must not be misrepresented; you must not *
19
* claim that you wrote the original software. If you use this software *
20
* in a product, an acknowledgment in the product documentation would be *
21
* appreciated but is not required. *
22
* 2. Altered source versions must be plainly marked as such, and must not be *
23
* misrepresented as being the original software. *
24
* 3. This notice may not be removed or altered from any source distribution. *
25
* *
26
* The polygon rasterization is heavily based on stb_truetype rasterizer *
27
* by Sean Barrett - http://nothings.org/ *
28
* ============================================================================ */
29
34
35
#ifndef NANOSVGRASTR_HPP
36
#define NANOSVGRASTR_HPP
37
38
#include "
nanosvg.hpp
"
39
40
namespace
nsvg
{
41
namespace
cstyle {
42
#define SUBSAMPLES 5
43
#define FIXSHIFT 10
44
#define FIX (1 << FIXSHIFT)
45
#define FIXMASK (FIX-1)
46
#define MEMPAGE_SIZE 1024
47
48
struct
Edge
{
49
float
x0,y0, x1,y1;
50
int
dir;
51
52
Edge
* next;
53
};
54
55
struct
Point
{
56
float
x, y;
57
float
dx, dy;
58
float
len;
59
float
dmx, dmy;
60
unsigned
char
flags;
61
};
62
63
struct
ActiveEdge
{
64
int
x,dx;
65
float
ey;
66
int
dir;
67
68
ActiveEdge
*next;
69
};
70
71
struct
MemPage
{
72
unsigned
char
mem[MEMPAGE_SIZE];
73
int
size;
74
75
MemPage
* next;
76
};
77
78
struct
CachedPaint
{
79
PaintType type;
80
SpreadType spread;
81
float
xform[6];
82
unsigned
int
colors[256];
83
};
84
85
struct
RasterizerStruct
86
{
87
float
px, py;
88
89
float
tessTol;
90
float
distTol;
91
92
Edge
* edges;
93
int
nedges;
94
int
cedges;
95
96
Point
* points;
97
int
npoints;
98
int
cpoints;
99
100
Point
* points2;
101
int
npoints2;
102
int
cpoints2;
103
104
ActiveEdge
* freelist;
105
MemPage
* pages;
106
MemPage
* curpage;
107
108
unsigned
char
* scanline;
109
int
cscanline;
110
111
unsigned
char
* bitmap;
112
int
width, height, stride;
113
};
114
115
// Allocated rasterizer context.
116
RasterizerStruct
* createRasterizer();
117
118
// Rasterizes SVG image, returns RGBA image (non-premultiplied alpha)
119
// r - pointer to rasterizer context
120
// image - pointer to image to rasterize
121
// tx,ty - image offset (applied after scaling)
122
// scale - image scale
123
// dst - pointer to destination image data, 4 bytes per pixel (RGBA)
124
// w - width of the image to render
125
// h - height of the image to render
126
// stride - number of bytes per scaleline in the destination buffer
127
void
rasterize(
RasterizerStruct
* r,
128
ImageStruct
* image,
float
tx,
float
ty,
float
scale,
129
unsigned
char
* dst,
int
w,
int
h,
int
stride);
130
131
// Deletes rasterizer context.
132
void
deleteRasterizer(
RasterizerStruct
*);
133
}
134
}
135
136
#endif // NANOSVGRASTR_HPP
nsvg::cstyle::RasterizerStruct
Definition:
nanosvgrastr.hpp:85
nsvg::cstyle::Point
Definition:
nanosvgrastr.hpp:55
nsvg
Nanosvg++ namespace.
Definition:
enums.hpp:15
nsvg::cstyle::Edge
Definition:
nanosvgrastr.hpp:48
nsvg::cstyle::MemPage
Definition:
nanosvgrastr.hpp:71
nanosvg.hpp
Nanosvg++ declarations.
nsvg::cstyle::ActiveEdge
Definition:
nanosvgrastr.hpp:63
nsvg::cstyle::CachedPaint
Definition:
nanosvgrastr.hpp:78
nsvg::cstyle::ImageStruct
Definition:
nanosvg.hpp:122
Generated by
1.8.13