FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/src/_backend_agg_wrapper.cpp at main · commit-0/matplotlib · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
commit-0
/
matplotlib
Public
forked from
matplotlib/matplotlib
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
src
/
_backend_agg_wrapper.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
283 lines (251 loc) · 10.1 KB
Breadcrumbs
matplotlib
/
src
/
_backend_agg_wrapper.cpp
Copy path
File metadata and controls
283 lines (251 loc) · 10.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#
include
<
pybind11/pybind11.h
>
#
include
<
pybind11/numpy.h
>
#
include
<
pybind11/stl.h
>
#
include
"
mplutils.h
"
#
include
"
py_converters.h
"
#
include
"
_backend_agg.h
"
namespace
py
=
pybind11;
using
namespace
pybind11
::literals
;
/*
*********************************************************************
* BufferRegion
*
*/
/*
TODO: This doesn't seem to be used internally. Remove?
*/
static
void
PyBufferRegion_set_x
(BufferRegion *self,
int
x)
{
self->
get_rect
().
x1
= x;
}
static
void
PyBufferRegion_set_y
(BufferRegion *self,
int
y)
{
self->
get_rect
().
y1
= y;
}
static
py::object
PyBufferRegion_get_extents
(BufferRegion *self)
{
agg::rect_i rect = self->
get_rect
();
return
py::make_tuple
(rect.
x1
, rect.
y1
, rect.
x2
, rect.
y2
);
}
/*
*********************************************************************
* RendererAgg
*
*/
static
void
PyRendererAgg_draw_path
(RendererAgg *self,
GCAgg &gc,
mpl::PathIterator path,
agg::trans_affine trans,
py::object rgbFace)
{
agg::rgba face = rgbFace.
cast
<agg::rgba>();
if
(!rgbFace.
is_none
()) {
if
(gc.
forced_alpha
|| rgbFace.
cast
<py::sequence>().
size
() ==
3
) {
face.
a
= gc.
alpha
;
}
}
self->
draw_path
(gc, path, trans, face);
}
static
void
PyRendererAgg_draw_text_image
(RendererAgg *self,
py::
array_t
<agg::int8u, py::array::c_style | py::array::forcecast> image_obj,
std::variant<
double
,
int
> vx,
std::variant<
double
,
int
> vy,
double
angle,
GCAgg &gc)
{
int
x, y;
if
(
auto
value = std::get_if<
double
>(&vx)) {
auto
api =
py::module_::import
(
"
matplotlib._api
"
);
auto
warn = api.
attr
(
"
warn_deprecated
"
);
warn
(
"
since
"
_a=
"
3.10
"
,
"
name
"
_a=
"
x
"
,
"
obj_type
"
_a=
"
parameter as float
"
,
"
alternative
"
_a=
"
int(x)
"
);
x =
static_cast
<
int
>(*value);
}
else
if
(
auto
value = std::get_if<
int
>(&vx)) {
x = *value;
}
else
{
throw
std::runtime_error
(
"
Should not happen
"
);
}
if
(
auto
value = std::get_if<
double
>(&vy)) {
auto
api =
py::module_::import
(
"
matplotlib._api
"
);
auto
warn = api.
attr
(
"
warn_deprecated
"
);
warn
(
"
since
"
_a=
"
3.10
"
,
"
name
"
_a=
"
y
"
,
"
obj_type
"
_a=
"
parameter as float
"
,
"
alternative
"
_a=
"
int(y)
"
);
y =
static_cast
<
int
>(*value);
}
else
if
(
auto
value = std::get_if<
int
>(&vy)) {
y = *value;
}
else
{
throw
std::runtime_error
(
"
Should not happen
"
);
}
//
TODO: This really shouldn't be mutable, but Agg's renderer buffers aren't const.
auto
image = image_obj.
mutable_unchecked
<
2
>();
self->
draw_text_image
(gc, image, x, y, angle);
}
static
void
PyRendererAgg_draw_markers
(RendererAgg *self,
GCAgg &gc,
mpl::PathIterator marker_path,
agg::trans_affine marker_path_trans,
mpl::PathIterator path,
agg::trans_affine trans,
py::object rgbFace)
{
agg::rgba face = rgbFace.
cast
<agg::rgba>();
if
(!rgbFace.
is_none
()) {
if
(gc.
forced_alpha
|| rgbFace.
cast
<py::sequence>().
size
() ==
3
) {
face.
a
= gc.
alpha
;
}
}
self->
draw_markers
(gc, marker_path, marker_path_trans, path, trans, face);
}
static
void
PyRendererAgg_draw_image
(RendererAgg *self,
GCAgg &gc,
double
x,
double
y,
py::
array_t
<agg::int8u, py::array::c_style | py::array::forcecast> image_obj)
{
//
TODO: This really shouldn't be mutable, but Agg's renderer buffers aren't const.
auto
image = image_obj.
mutable_unchecked
<
3
>();
x =
mpl_round
(x);
y =
mpl_round
(y);
gc.
alpha
=
1.0
;
self->
draw_image
(gc, x, y, image);
}
static
void
PyRendererAgg_draw_path_collection
(RendererAgg *self,
GCAgg &gc,
agg::trans_affine master_transform,
mpl::PathGenerator paths,
py::
array_t
<
double
> transforms_obj,
py::
array_t
<
double
> offsets_obj,
agg::trans_affine offset_trans,
py::
array_t
<
double
> facecolors_obj,
py::
array_t
<
double
> edgecolors_obj,
py::
array_t
<
double
> linewidths_obj,
DashesVector dashes,
py::
array_t
<
uint8_t
> antialiaseds_obj,
py::object
Py_UNUSED
(ignored_obj),
//
offset position is no longer used
py::object Py_UNUSED(offset_position_obj))
{
auto
transforms =
convert_transforms
(transforms_obj);
auto
offsets =
convert_points
(offsets_obj);
auto
facecolors =
convert_colors
(facecolors_obj);
auto
edgecolors =
convert_colors
(edgecolors_obj);
auto
linewidths = linewidths_obj.
unchecked
<
1
>();
auto
antialiaseds = antialiaseds_obj.
unchecked
<
1
>();
self->
draw_path_collection
(gc,
master_transform,
paths,
transforms,
offsets,
offset_trans,
facecolors,
edgecolors,
linewidths,
dashes,
antialiaseds);
}
static
void
PyRendererAgg_draw_quad_mesh
(RendererAgg *self,
GCAgg &gc,
agg::trans_affine master_transform,
unsigned
int
mesh_width,
unsigned
int
mesh_height,
py::
array_t
<
double
, py::array::c_style | py::array::forcecast> coordinates_obj,
py::
array_t
<
double
> offsets_obj,
agg::trans_affine offset_trans,
py::
array_t
<
double
> facecolors_obj,
bool
antialiased,
py::
array_t
<
double
> edgecolors_obj)
{
auto
coordinates = coordinates_obj.
mutable_unchecked
<
3
>();
auto
offsets =
convert_points
(offsets_obj);
auto
facecolors =
convert_colors
(facecolors_obj);
auto
edgecolors =
convert_colors
(edgecolors_obj);
self->
draw_quad_mesh
(gc,
master_transform,
mesh_width,
mesh_height,
coordinates,
offsets,
offset_trans,
facecolors,
antialiased,
edgecolors);
}
static
void
PyRendererAgg_draw_gouraud_triangles
(RendererAgg *self,
GCAgg &gc,
py::
array_t
<
double
> points_obj,
py::
array_t
<
double
> colors_obj,
agg::trans_affine trans)
{
auto
points = points_obj.
unchecked
<
3
>();
auto
colors = colors_obj.
unchecked
<
3
>();
self->
draw_gouraud_triangles
(gc, points, colors, trans);
}
PYBIND11_MODULE
(_backend_agg, m, py::mod_gil_not_used())
{
py::class_<RendererAgg>(m,
"
RendererAgg
"
,
py::buffer_protocol
())
.
def
(py::init<
unsigned
int
,
unsigned
int
,
double
>(),
"
width
"
_a,
"
height
"
_a,
"
dpi
"
_a)
.
def
(
"
draw_path
"
, &PyRendererAgg_draw_path,
"
gc
"
_a,
"
path
"
_a,
"
trans
"
_a,
"
face
"
_a =
nullptr
)
.
def
(
"
draw_markers
"
, &PyRendererAgg_draw_markers,
"
gc
"
_a,
"
marker_path
"
_a,
"
marker_path_trans
"
_a,
"
path
"
_a,
"
trans
"
_a,
"
face
"
_a =
nullptr
)
.
def
(
"
draw_text_image
"
, &PyRendererAgg_draw_text_image,
"
image
"
_a,
"
x
"
_a,
"
y
"
_a,
"
angle
"
_a,
"
gc
"
_a)
.
def
(
"
draw_image
"
, &PyRendererAgg_draw_image,
"
gc
"
_a,
"
x
"
_a,
"
y
"
_a,
"
image
"
_a)
.
def
(
"
draw_path_collection
"
, &PyRendererAgg_draw_path_collection,
"
gc
"
_a,
"
master_transform
"
_a,
"
paths
"
_a,
"
transforms
"
_a,
"
offsets
"
_a,
"
offset_trans
"
_a,
"
facecolors
"
_a,
"
edgecolors
"
_a,
"
linewidths
"
_a,
"
dashes
"
_a,
"
antialiaseds
"
_a,
"
ignored
"
_a,
"
offset_position
"
_a)
.
def
(
"
draw_quad_mesh
"
, &PyRendererAgg_draw_quad_mesh,
"
gc
"
_a,
"
master_transform
"
_a,
"
mesh_width
"
_a,
"
mesh_height
"
_a,
"
coordinates
"
_a,
"
offsets
"
_a,
"
offset_trans
"
_a,
"
facecolors
"
_a,
"
antialiased
"
_a,
"
edgecolors
"
_a)
.
def
(
"
draw_gouraud_triangles
"
, &PyRendererAgg_draw_gouraud_triangles,
"
gc
"
_a,
"
points
"
_a,
"
colors
"
_a,
"
trans
"
_a =
nullptr
)
.
def
(
"
clear
"
, &RendererAgg::clear)
.
def
(
"
copy_from_bbox
"
, &RendererAgg::copy_from_bbox,
"
bbox
"
_a)
.
def
(
"
restore_region
"
,
py::overload_cast<BufferRegion&>(&RendererAgg::restore_region),
"
region
"
_a)
.
def
(
"
restore_region
"
,
py::overload_cast<BufferRegion&,
int
,
int
,
int
,
int
,
int
,
int
>(&RendererAgg::restore_region),
"
region
"
_a,
"
xx1
"
_a,
"
yy1
"
_a,
"
xx2
"
_a,
"
yy2
"
_a,
"
x
"
_a,
"
y
"
_a)
.
def_buffer
([](RendererAgg *renderer) -> py::buffer_info {
std::vector<py::
ssize_t
> shape {
renderer->
get_height
(),
renderer->
get_width
(),
4
};
std::vector<py::
ssize_t
> strides {
renderer->
get_width
() *
4
,
4
,
1
};
return
py::buffer_info
(renderer->
pixBuffer
, shape, strides);
});
py::class_<BufferRegion>(m,
"
BufferRegion
"
,
py::buffer_protocol
())
//
BufferRegion is not constructible from Python, thus no py::init is added.
.
def
(
"
set_x
"
, &PyBufferRegion_set_x)
.
def
(
"
set_y
"
, &PyBufferRegion_set_y)
.
def
(
"
get_extents
"
, &PyBufferRegion_get_extents)
.
def_buffer
([](BufferRegion *buffer) -> py::buffer_info {
std::vector<py::
ssize_t
> shape {
buffer->
get_height
(),
buffer->
get_width
(),
4
};
std::vector<py::
ssize_t
> strides {
buffer->
get_width
() *
4
,
4
,
1
};
return
py::buffer_info
(buffer->
get_data
(), shape, strides);
});
}
Back
|
FazBrowse Home
|
New Git URL