Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5ed1056

Browse files
committed
Add a pybind11 type caster for GCAgg and its requirements
1 parent6517f3f commit5ed1056

File tree

5 files changed

+184
-59
lines changed

5 files changed

+184
-59
lines changed

‎src/_backend_agg_basic_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
#include"agg_math_stroke.h"
1111
#include"path_converters.h"
1212

13+
#ifndef AVOID_NUMPY_HEADERS
1314
#include"py_adaptors.h"
15+
#else
16+
namespacepy {
17+
classPathIterator;
18+
}
19+
#endif
1420

1521
structClipPath
1622
{

‎src/_backend_agg_wrapper.cpp

Lines changed: 12 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include"mplutils.h"
44
#include"numpy_cpp.h"
55
#include"py_converters.h"
6+
#defineAVOID_NUMPY_HEADERS
67
#include"py_converters_11.h"
78
#include"_backend_agg.h"
89

@@ -40,22 +41,13 @@ PyBufferRegion_get_extents(BufferRegion *self)
4041

4142
staticvoid
4243
PyRendererAgg_draw_path(RendererAgg *self,
43-
pybind11::object gc_obj,
44-
pybind11::object path_obj,
44+
GCAgg &gc,
45+
py::PathIterator path,
4546
agg::trans_affine trans,
4647
pybind11::object face_obj)
4748
{
48-
GCAgg gc;
49-
py::PathIterator path;
5049
agg::rgba face;
5150

52-
if (!convert_gcagg(gc_obj.ptr(), &gc)) {
53-
throwpybind11::error_already_set();
54-
}
55-
if (!convert_path(path_obj.ptr(), &path)) {
56-
throwpybind11::error_already_set();
57-
}
58-
5951
if (!convert_face(face_obj.ptr(), gc, &face)) {
6052
throwpybind11::error_already_set();
6153
}
@@ -69,45 +61,28 @@ PyRendererAgg_draw_text_image(RendererAgg *self,
6961
double x,
7062
double y,
7163
double angle,
72-
pybind11::object gc_obj)
64+
GCAgg &gc)
7365
{
7466
numpy::array_view<agg::int8u,2> image;
75-
GCAgg gc;
7667

7768
if (!image.converter_contiguous(image_obj.ptr(), &image)) {
7869
throwpybind11::error_already_set();
7970
}
80-
if (!convert_gcagg(gc_obj.ptr(), &gc)) {
81-
throwpybind11::error_already_set();
82-
}
8371

8472
self->draw_text_image(gc, image, x, y, angle);
8573
}
8674

8775
staticvoid
8876
PyRendererAgg_draw_markers(RendererAgg *self,
89-
pybind11::object gc_obj,
90-
pybind11::object marker_path_obj,
77+
GCAgg &gc,
78+
py::PathIterator marker_path,
9179
agg::trans_affine marker_path_trans,
92-
pybind11::object path_obj,
80+
py::PathIterator path,
9381
agg::trans_affine trans,
9482
pybind11::object face_obj)
9583
{
96-
GCAgg gc;
97-
py::PathIterator marker_path;
98-
py::PathIterator path;
9984
agg::rgba face;
10085

101-
if (!convert_gcagg(gc_obj.ptr(), &gc)) {
102-
throwpybind11::error_already_set();
103-
}
104-
if (!convert_path(marker_path_obj.ptr(), &marker_path)) {
105-
throwpybind11::error_already_set();
106-
}
107-
if (!convert_path(path_obj.ptr(), &path)) {
108-
throwpybind11::error_already_set();
109-
}
110-
11186
if (!convert_face(face_obj.ptr(), gc, &face)) {
11287
throwpybind11::error_already_set();
11388
}
@@ -117,17 +92,13 @@ PyRendererAgg_draw_markers(RendererAgg *self,
11792

11893
staticvoid
11994
PyRendererAgg_draw_image(RendererAgg *self,
120-
pybind11::object gc_obj,
95+
GCAgg &gc,
12196
double x,
12297
double y,
12398
pybind11::array_t<agg::int8u, pybind11::array::c_style> image_obj)
12499
{
125-
GCAgg gc;
126100
numpy::array_view<agg::int8u,3> image;
127101

128-
if (!convert_gcagg(gc_obj.ptr(), &gc)) {
129-
throwpybind11::error_already_set();
130-
}
131102
if (!image.set(image_obj.ptr())) {
132103
throwpybind11::error_already_set();
133104
}
@@ -141,7 +112,7 @@ PyRendererAgg_draw_image(RendererAgg *self,
141112

142113
staticvoid
143114
PyRendererAgg_draw_path_collection(RendererAgg *self,
144-
pybind11::object gc_obj,
115+
GCAgg &gc,
145116
agg::trans_affine master_transform,
146117
pybind11::object paths_obj,
147118
pybind11::object transforms_obj,
@@ -150,25 +121,20 @@ PyRendererAgg_draw_path_collection(RendererAgg *self,
150121
pybind11::object facecolors_obj,
151122
pybind11::object edgecolors_obj,
152123
pybind11::object linewidths_obj,
153-
pybind11::object dashes_obj,
124+
DashesVector dashes,
154125
pybind11::object antialiaseds_obj,
155126
pybind11::objectPy_UNUSED(ignored_obj),
156127
// offset position is no longer used
157128
pybind11::object Py_UNUSED(offset_position_obj))
158129
{
159-
GCAgg gc;
160130
py::PathGenerator paths;
161131
numpy::array_view<constdouble,3> transforms;
162132
numpy::array_view<constdouble,2> offsets;
163133
numpy::array_view<constdouble,2> facecolors;
164134
numpy::array_view<constdouble,2> edgecolors;
165135
numpy::array_view<constdouble,1> linewidths;
166-
DashesVector dashes;
167136
numpy::array_view<constuint8_t,1> antialiaseds;
168137

169-
if (!convert_gcagg(gc_obj.ptr(), &gc)) {
170-
throwpybind11::error_already_set();
171-
}
172138
if (!convert_pathgen(paths_obj.ptr(), &paths)) {
173139
throwpybind11::error_already_set();
174140
}
@@ -187,9 +153,6 @@ PyRendererAgg_draw_path_collection(RendererAgg *self,
187153
if (!linewidths.converter(linewidths_obj.ptr(), &linewidths)) {
188154
throwpybind11::error_already_set();
189155
}
190-
if (!convert_dashes_vector(dashes_obj.ptr(), &dashes)) {
191-
throwpybind11::error_already_set();
192-
}
193156
if (!antialiaseds.converter(antialiaseds_obj.ptr(), &antialiaseds)) {
194157
throwpybind11::error_already_set();
195158
}
@@ -209,7 +172,7 @@ PyRendererAgg_draw_path_collection(RendererAgg *self,
209172

210173
staticvoid
211174
PyRendererAgg_draw_quad_mesh(RendererAgg *self,
212-
pybind11::object gc_obj,
175+
GCAgg &gc,
213176
agg::trans_affine master_transform,
214177
unsignedint mesh_width,
215178
unsignedint mesh_height,
@@ -220,15 +183,11 @@ PyRendererAgg_draw_quad_mesh(RendererAgg *self,
220183
bool antialiased,
221184
pybind11::object edgecolors_obj)
222185
{
223-
GCAgg gc;
224186
numpy::array_view<constdouble,3> coordinates;
225187
numpy::array_view<constdouble,2> offsets;
226188
numpy::array_view<constdouble,2> facecolors;
227189
numpy::array_view<constdouble,2> edgecolors;
228190

229-
if (!convert_gcagg(gc_obj.ptr(), &gc)) {
230-
throwpybind11::error_already_set();
231-
}
232191
if (!coordinates.converter(coordinates_obj.ptr(), &coordinates)) {
233192
throwpybind11::error_already_set();
234193
}
@@ -256,18 +215,14 @@ PyRendererAgg_draw_quad_mesh(RendererAgg *self,
256215

257216
staticvoid
258217
PyRendererAgg_draw_gouraud_triangles(RendererAgg *self,
259-
pybind11::object gc_obj,
218+
GCAgg &gc,
260219
pybind11::object points_obj,
261220
pybind11::object colors_obj,
262221
agg::trans_affine trans)
263222
{
264-
GCAgg gc;
265223
numpy::array_view<constdouble,3> points;
266224
numpy::array_view<constdouble,3> colors;
267225

268-
if (!convert_gcagg(gc_obj.ptr(), &gc)) {
269-
throwpybind11::error_already_set();
270-
}
271226
if (!points.converter(points_obj.ptr(), &points)) {
272227
throwpybind11::error_already_set();
273228
}

‎src/py_converters.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ int convert_pathgen(PyObject *obj, void *pathgenp)
415415
intconvert_clippath(PyObject *clippath_tuple,void *clippathp)
416416
{
417417
ClipPath *clippath = (ClipPath *)clippathp;
418-
py::PathIterator path;
419-
agg::trans_affine trans;
420418

421419
if (clippath_tuple !=NULL && clippath_tuple != Py_None) {
422420
if (!PyArg_ParseTuple(clippath_tuple,

‎src/py_converters_11.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#defineNO_IMPORT_ARRAY
12
#include"py_converters_11.h"
23

34
voidconvert_trans_affine(const pybind11::object& transform, agg::trans_affine& affine)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp