_backend_agg_wrapper.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. #include "mplutils.h"
  2. #include "numpy_cpp.h"
  3. #include "py_converters.h"
  4. #include "_backend_agg.h"
  5. typedef struct
  6. {
  7. PyObject_HEAD
  8. RendererAgg *x;
  9. Py_ssize_t shape[3];
  10. Py_ssize_t strides[3];
  11. Py_ssize_t suboffsets[3];
  12. } PyRendererAgg;
  13. static PyTypeObject PyRendererAggType;
  14. typedef struct
  15. {
  16. PyObject_HEAD
  17. BufferRegion *x;
  18. Py_ssize_t shape[3];
  19. Py_ssize_t strides[3];
  20. Py_ssize_t suboffsets[3];
  21. } PyBufferRegion;
  22. static PyTypeObject PyBufferRegionType;
  23. /**********************************************************************
  24. * BufferRegion
  25. * */
  26. static PyObject *PyBufferRegion_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  27. {
  28. PyBufferRegion *self;
  29. self = (PyBufferRegion *)type->tp_alloc(type, 0);
  30. self->x = NULL;
  31. return (PyObject *)self;
  32. }
  33. static void PyBufferRegion_dealloc(PyBufferRegion *self)
  34. {
  35. delete self->x;
  36. Py_TYPE(self)->tp_free((PyObject *)self);
  37. }
  38. static PyObject *PyBufferRegion_to_string(PyBufferRegion *self, PyObject *args)
  39. {
  40. char const* msg =
  41. "BufferRegion.to_string is deprecated since Matplotlib 3.7 and will "
  42. "be removed two minor releases later; use np.asarray(region) instead.";
  43. if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1)) {
  44. return NULL;
  45. }
  46. return PyBytes_FromStringAndSize((const char *)self->x->get_data(),
  47. (Py_ssize_t) self->x->get_height() * self->x->get_stride());
  48. }
  49. /* TODO: This doesn't seem to be used internally. Remove? */
  50. static PyObject *PyBufferRegion_set_x(PyBufferRegion *self, PyObject *args)
  51. {
  52. int x;
  53. if (!PyArg_ParseTuple(args, "i:set_x", &x)) {
  54. return NULL;
  55. }
  56. self->x->get_rect().x1 = x;
  57. Py_RETURN_NONE;
  58. }
  59. static PyObject *PyBufferRegion_set_y(PyBufferRegion *self, PyObject *args)
  60. {
  61. int y;
  62. if (!PyArg_ParseTuple(args, "i:set_y", &y)) {
  63. return NULL;
  64. }
  65. self->x->get_rect().y1 = y;
  66. Py_RETURN_NONE;
  67. }
  68. static PyObject *PyBufferRegion_get_extents(PyBufferRegion *self, PyObject *args)
  69. {
  70. agg::rect_i rect = self->x->get_rect();
  71. return Py_BuildValue("IIII", rect.x1, rect.y1, rect.x2, rect.y2);
  72. }
  73. static PyObject *PyBufferRegion_to_string_argb(PyBufferRegion *self, PyObject *args)
  74. {
  75. char const* msg =
  76. "BufferRegion.to_string_argb is deprecated since Matplotlib 3.7 and "
  77. "will be removed two minor releases later; use "
  78. "np.take(region, [2, 1, 0, 3], axis=2) instead.";
  79. if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1)) {
  80. return NULL;
  81. }
  82. PyObject *bufobj;
  83. uint8_t *buf;
  84. Py_ssize_t height, stride;
  85. height = self->x->get_height();
  86. stride = self->x->get_stride();
  87. bufobj = PyBytes_FromStringAndSize(NULL, height * stride);
  88. buf = (uint8_t *)PyBytes_AS_STRING(bufobj);
  89. CALL_CPP_CLEANUP("to_string_argb", (self->x->to_string_argb(buf)), Py_DECREF(bufobj));
  90. return bufobj;
  91. }
  92. int PyBufferRegion_get_buffer(PyBufferRegion *self, Py_buffer *buf, int flags)
  93. {
  94. Py_INCREF(self);
  95. buf->obj = (PyObject *)self;
  96. buf->buf = self->x->get_data();
  97. buf->len = (Py_ssize_t)self->x->get_width() * (Py_ssize_t)self->x->get_height() * 4;
  98. buf->readonly = 0;
  99. buf->format = (char *)"B";
  100. buf->ndim = 3;
  101. self->shape[0] = self->x->get_height();
  102. self->shape[1] = self->x->get_width();
  103. self->shape[2] = 4;
  104. buf->shape = self->shape;
  105. self->strides[0] = self->x->get_width() * 4;
  106. self->strides[1] = 4;
  107. self->strides[2] = 1;
  108. buf->strides = self->strides;
  109. buf->suboffsets = NULL;
  110. buf->itemsize = 1;
  111. buf->internal = NULL;
  112. return 1;
  113. }
  114. static PyTypeObject *PyBufferRegion_init_type()
  115. {
  116. static PyMethodDef methods[] = {
  117. { "to_string", (PyCFunction)PyBufferRegion_to_string, METH_NOARGS, NULL },
  118. { "to_string_argb", (PyCFunction)PyBufferRegion_to_string_argb, METH_NOARGS, NULL },
  119. { "set_x", (PyCFunction)PyBufferRegion_set_x, METH_VARARGS, NULL },
  120. { "set_y", (PyCFunction)PyBufferRegion_set_y, METH_VARARGS, NULL },
  121. { "get_extents", (PyCFunction)PyBufferRegion_get_extents, METH_NOARGS, NULL },
  122. { NULL }
  123. };
  124. static PyBufferProcs buffer_procs;
  125. buffer_procs.bf_getbuffer = (getbufferproc)PyBufferRegion_get_buffer;
  126. PyBufferRegionType.tp_name = "matplotlib.backends._backend_agg.BufferRegion";
  127. PyBufferRegionType.tp_basicsize = sizeof(PyBufferRegion);
  128. PyBufferRegionType.tp_dealloc = (destructor)PyBufferRegion_dealloc;
  129. PyBufferRegionType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  130. PyBufferRegionType.tp_methods = methods;
  131. PyBufferRegionType.tp_new = PyBufferRegion_new;
  132. PyBufferRegionType.tp_as_buffer = &buffer_procs;
  133. return &PyBufferRegionType;
  134. }
  135. /**********************************************************************
  136. * RendererAgg
  137. * */
  138. static PyObject *PyRendererAgg_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  139. {
  140. PyRendererAgg *self;
  141. self = (PyRendererAgg *)type->tp_alloc(type, 0);
  142. self->x = NULL;
  143. return (PyObject *)self;
  144. }
  145. static int PyRendererAgg_init(PyRendererAgg *self, PyObject *args, PyObject *kwds)
  146. {
  147. unsigned int width;
  148. unsigned int height;
  149. double dpi;
  150. int debug = 0;
  151. if (!PyArg_ParseTuple(args, "IId|i:RendererAgg", &width, &height, &dpi, &debug)) {
  152. return -1;
  153. }
  154. if (dpi <= 0.0) {
  155. PyErr_SetString(PyExc_ValueError, "dpi must be positive");
  156. return -1;
  157. }
  158. if (width >= 1 << 16 || height >= 1 << 16) {
  159. PyErr_Format(
  160. PyExc_ValueError,
  161. "Image size of %dx%d pixels is too large. "
  162. "It must be less than 2^16 in each direction.",
  163. width, height);
  164. return -1;
  165. }
  166. CALL_CPP_INIT("RendererAgg", self->x = new RendererAgg(width, height, dpi))
  167. return 0;
  168. }
  169. static void PyRendererAgg_dealloc(PyRendererAgg *self)
  170. {
  171. delete self->x;
  172. Py_TYPE(self)->tp_free((PyObject *)self);
  173. }
  174. static PyObject *PyRendererAgg_draw_path(PyRendererAgg *self, PyObject *args)
  175. {
  176. GCAgg gc;
  177. py::PathIterator path;
  178. agg::trans_affine trans;
  179. PyObject *faceobj = NULL;
  180. agg::rgba face;
  181. if (!PyArg_ParseTuple(args,
  182. "O&O&O&|O:draw_path",
  183. &convert_gcagg,
  184. &gc,
  185. &convert_path,
  186. &path,
  187. &convert_trans_affine,
  188. &trans,
  189. &faceobj)) {
  190. return NULL;
  191. }
  192. if (!convert_face(faceobj, gc, &face)) {
  193. return NULL;
  194. }
  195. CALL_CPP("draw_path", (self->x->draw_path(gc, path, trans, face)));
  196. Py_RETURN_NONE;
  197. }
  198. static PyObject *PyRendererAgg_draw_text_image(PyRendererAgg *self, PyObject *args)
  199. {
  200. numpy::array_view<agg::int8u, 2> image;
  201. double x;
  202. double y;
  203. double angle;
  204. GCAgg gc;
  205. if (!PyArg_ParseTuple(args,
  206. "O&dddO&:draw_text_image",
  207. &image.converter_contiguous,
  208. &image,
  209. &x,
  210. &y,
  211. &angle,
  212. &convert_gcagg,
  213. &gc)) {
  214. return NULL;
  215. }
  216. CALL_CPP("draw_text_image", (self->x->draw_text_image(gc, image, x, y, angle)));
  217. Py_RETURN_NONE;
  218. }
  219. PyObject *PyRendererAgg_draw_markers(PyRendererAgg *self, PyObject *args)
  220. {
  221. GCAgg gc;
  222. py::PathIterator marker_path;
  223. agg::trans_affine marker_path_trans;
  224. py::PathIterator path;
  225. agg::trans_affine trans;
  226. PyObject *faceobj = NULL;
  227. agg::rgba face;
  228. if (!PyArg_ParseTuple(args,
  229. "O&O&O&O&O&|O:draw_markers",
  230. &convert_gcagg,
  231. &gc,
  232. &convert_path,
  233. &marker_path,
  234. &convert_trans_affine,
  235. &marker_path_trans,
  236. &convert_path,
  237. &path,
  238. &convert_trans_affine,
  239. &trans,
  240. &faceobj)) {
  241. return NULL;
  242. }
  243. if (!convert_face(faceobj, gc, &face)) {
  244. return NULL;
  245. }
  246. CALL_CPP("draw_markers",
  247. (self->x->draw_markers(gc, marker_path, marker_path_trans, path, trans, face)));
  248. Py_RETURN_NONE;
  249. }
  250. static PyObject *PyRendererAgg_draw_image(PyRendererAgg *self, PyObject *args)
  251. {
  252. GCAgg gc;
  253. double x;
  254. double y;
  255. numpy::array_view<agg::int8u, 3> image;
  256. if (!PyArg_ParseTuple(args,
  257. "O&ddO&:draw_image",
  258. &convert_gcagg,
  259. &gc,
  260. &x,
  261. &y,
  262. &image.converter_contiguous,
  263. &image)) {
  264. return NULL;
  265. }
  266. x = mpl_round(x);
  267. y = mpl_round(y);
  268. gc.alpha = 1.0;
  269. CALL_CPP("draw_image", (self->x->draw_image(gc, x, y, image)));
  270. Py_RETURN_NONE;
  271. }
  272. static PyObject *
  273. PyRendererAgg_draw_path_collection(PyRendererAgg *self, PyObject *args)
  274. {
  275. GCAgg gc;
  276. agg::trans_affine master_transform;
  277. py::PathGenerator paths;
  278. numpy::array_view<const double, 3> transforms;
  279. numpy::array_view<const double, 2> offsets;
  280. agg::trans_affine offset_trans;
  281. numpy::array_view<const double, 2> facecolors;
  282. numpy::array_view<const double, 2> edgecolors;
  283. numpy::array_view<const double, 1> linewidths;
  284. DashesVector dashes;
  285. numpy::array_view<const uint8_t, 1> antialiaseds;
  286. PyObject *ignored;
  287. PyObject *offset_position; // offset position is no longer used
  288. if (!PyArg_ParseTuple(args,
  289. "O&O&O&O&O&O&O&O&O&O&O&OO:draw_path_collection",
  290. &convert_gcagg,
  291. &gc,
  292. &convert_trans_affine,
  293. &master_transform,
  294. &convert_pathgen,
  295. &paths,
  296. &convert_transforms,
  297. &transforms,
  298. &convert_points,
  299. &offsets,
  300. &convert_trans_affine,
  301. &offset_trans,
  302. &convert_colors,
  303. &facecolors,
  304. &convert_colors,
  305. &edgecolors,
  306. &linewidths.converter,
  307. &linewidths,
  308. &convert_dashes_vector,
  309. &dashes,
  310. &antialiaseds.converter,
  311. &antialiaseds,
  312. &ignored,
  313. &offset_position)) {
  314. return NULL;
  315. }
  316. CALL_CPP("draw_path_collection",
  317. (self->x->draw_path_collection(gc,
  318. master_transform,
  319. paths,
  320. transforms,
  321. offsets,
  322. offset_trans,
  323. facecolors,
  324. edgecolors,
  325. linewidths,
  326. dashes,
  327. antialiaseds)));
  328. Py_RETURN_NONE;
  329. }
  330. static PyObject *PyRendererAgg_draw_quad_mesh(PyRendererAgg *self, PyObject *args)
  331. {
  332. GCAgg gc;
  333. agg::trans_affine master_transform;
  334. unsigned int mesh_width;
  335. unsigned int mesh_height;
  336. numpy::array_view<const double, 3> coordinates;
  337. numpy::array_view<const double, 2> offsets;
  338. agg::trans_affine offset_trans;
  339. numpy::array_view<const double, 2> facecolors;
  340. bool antialiased;
  341. numpy::array_view<const double, 2> edgecolors;
  342. if (!PyArg_ParseTuple(args,
  343. "O&O&IIO&O&O&O&O&O&:draw_quad_mesh",
  344. &convert_gcagg,
  345. &gc,
  346. &convert_trans_affine,
  347. &master_transform,
  348. &mesh_width,
  349. &mesh_height,
  350. &coordinates.converter,
  351. &coordinates,
  352. &convert_points,
  353. &offsets,
  354. &convert_trans_affine,
  355. &offset_trans,
  356. &convert_colors,
  357. &facecolors,
  358. &convert_bool,
  359. &antialiased,
  360. &convert_colors,
  361. &edgecolors)) {
  362. return NULL;
  363. }
  364. CALL_CPP("draw_quad_mesh",
  365. (self->x->draw_quad_mesh(gc,
  366. master_transform,
  367. mesh_width,
  368. mesh_height,
  369. coordinates,
  370. offsets,
  371. offset_trans,
  372. facecolors,
  373. antialiased,
  374. edgecolors)));
  375. Py_RETURN_NONE;
  376. }
  377. static PyObject *
  378. PyRendererAgg_draw_gouraud_triangle(PyRendererAgg *self, PyObject *args)
  379. {
  380. GCAgg gc;
  381. numpy::array_view<const double, 2> points;
  382. numpy::array_view<const double, 2> colors;
  383. agg::trans_affine trans;
  384. if (!PyArg_ParseTuple(args,
  385. "O&O&O&O&|O:draw_gouraud_triangle",
  386. &convert_gcagg,
  387. &gc,
  388. &points.converter,
  389. &points,
  390. &colors.converter,
  391. &colors,
  392. &convert_trans_affine,
  393. &trans)) {
  394. return NULL;
  395. }
  396. if (points.dim(0) != 3 || points.dim(1) != 2) {
  397. PyErr_Format(PyExc_ValueError,
  398. "points must have shape (3, 2), "
  399. "got (%" NPY_INTP_FMT ", %" NPY_INTP_FMT ")",
  400. points.dim(0), points.dim(1));
  401. return NULL;
  402. }
  403. if (colors.dim(0) != 3 || colors.dim(1) != 4) {
  404. PyErr_Format(PyExc_ValueError,
  405. "colors must have shape (3, 4), "
  406. "got (%" NPY_INTP_FMT ", %" NPY_INTP_FMT ")",
  407. colors.dim(0), colors.dim(1));
  408. return NULL;
  409. }
  410. CALL_CPP("draw_gouraud_triangle", (self->x->draw_gouraud_triangle(gc, points, colors, trans)));
  411. Py_RETURN_NONE;
  412. }
  413. static PyObject *
  414. PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args)
  415. {
  416. GCAgg gc;
  417. numpy::array_view<const double, 3> points;
  418. numpy::array_view<const double, 3> colors;
  419. agg::trans_affine trans;
  420. if (!PyArg_ParseTuple(args,
  421. "O&O&O&O&|O:draw_gouraud_triangles",
  422. &convert_gcagg,
  423. &gc,
  424. &points.converter,
  425. &points,
  426. &colors.converter,
  427. &colors,
  428. &convert_trans_affine,
  429. &trans)) {
  430. return NULL;
  431. }
  432. if (points.size() && !check_trailing_shape(points, "points", 3, 2)) {
  433. return NULL;
  434. }
  435. if (colors.size() && !check_trailing_shape(colors, "colors", 3, 4)) {
  436. return NULL;
  437. }
  438. if (points.size() != colors.size()) {
  439. PyErr_Format(PyExc_ValueError,
  440. "points and colors arrays must be the same length, got "
  441. "%" NPY_INTP_FMT " points and %" NPY_INTP_FMT "colors",
  442. points.dim(0), colors.dim(0));
  443. return NULL;
  444. }
  445. CALL_CPP("draw_gouraud_triangles", self->x->draw_gouraud_triangles(gc, points, colors, trans));
  446. Py_RETURN_NONE;
  447. }
  448. int PyRendererAgg_get_buffer(PyRendererAgg *self, Py_buffer *buf, int flags)
  449. {
  450. Py_INCREF(self);
  451. buf->obj = (PyObject *)self;
  452. buf->buf = self->x->pixBuffer;
  453. buf->len = (Py_ssize_t)self->x->get_width() * (Py_ssize_t)self->x->get_height() * 4;
  454. buf->readonly = 0;
  455. buf->format = (char *)"B";
  456. buf->ndim = 3;
  457. self->shape[0] = self->x->get_height();
  458. self->shape[1] = self->x->get_width();
  459. self->shape[2] = 4;
  460. buf->shape = self->shape;
  461. self->strides[0] = self->x->get_width() * 4;
  462. self->strides[1] = 4;
  463. self->strides[2] = 1;
  464. buf->strides = self->strides;
  465. buf->suboffsets = NULL;
  466. buf->itemsize = 1;
  467. buf->internal = NULL;
  468. return 1;
  469. }
  470. static PyObject *PyRendererAgg_clear(PyRendererAgg *self, PyObject *args)
  471. {
  472. CALL_CPP("clear", self->x->clear());
  473. Py_RETURN_NONE;
  474. }
  475. static PyObject *PyRendererAgg_copy_from_bbox(PyRendererAgg *self, PyObject *args)
  476. {
  477. agg::rect_d bbox;
  478. BufferRegion *reg;
  479. PyObject *regobj;
  480. if (!PyArg_ParseTuple(args, "O&:copy_from_bbox", &convert_rect, &bbox)) {
  481. return 0;
  482. }
  483. CALL_CPP("copy_from_bbox", (reg = self->x->copy_from_bbox(bbox)));
  484. regobj = PyBufferRegion_new(&PyBufferRegionType, NULL, NULL);
  485. ((PyBufferRegion *)regobj)->x = reg;
  486. return regobj;
  487. }
  488. static PyObject *PyRendererAgg_restore_region(PyRendererAgg *self, PyObject *args)
  489. {
  490. PyBufferRegion *regobj;
  491. int xx1 = 0, yy1 = 0, xx2 = 0, yy2 = 0, x = 0, y = 0;
  492. if (!PyArg_ParseTuple(args,
  493. "O!|iiiiii:restore_region",
  494. &PyBufferRegionType,
  495. &regobj,
  496. &xx1,
  497. &yy1,
  498. &xx2,
  499. &yy2,
  500. &x,
  501. &y)) {
  502. return 0;
  503. }
  504. if (PySequence_Size(args) == 1) {
  505. CALL_CPP("restore_region", self->x->restore_region(*(regobj->x)));
  506. } else {
  507. CALL_CPP("restore_region", self->x->restore_region(*(regobj->x), xx1, yy1, xx2, yy2, x, y));
  508. }
  509. Py_RETURN_NONE;
  510. }
  511. static PyTypeObject *PyRendererAgg_init_type()
  512. {
  513. static PyMethodDef methods[] = {
  514. {"draw_path", (PyCFunction)PyRendererAgg_draw_path, METH_VARARGS, NULL},
  515. {"draw_markers", (PyCFunction)PyRendererAgg_draw_markers, METH_VARARGS, NULL},
  516. {"draw_text_image", (PyCFunction)PyRendererAgg_draw_text_image, METH_VARARGS, NULL},
  517. {"draw_image", (PyCFunction)PyRendererAgg_draw_image, METH_VARARGS, NULL},
  518. {"draw_path_collection", (PyCFunction)PyRendererAgg_draw_path_collection, METH_VARARGS, NULL},
  519. {"draw_quad_mesh", (PyCFunction)PyRendererAgg_draw_quad_mesh, METH_VARARGS, NULL},
  520. {"draw_gouraud_triangle", (PyCFunction)PyRendererAgg_draw_gouraud_triangle, METH_VARARGS, NULL},
  521. {"draw_gouraud_triangles", (PyCFunction)PyRendererAgg_draw_gouraud_triangles, METH_VARARGS, NULL},
  522. {"clear", (PyCFunction)PyRendererAgg_clear, METH_NOARGS, NULL},
  523. {"copy_from_bbox", (PyCFunction)PyRendererAgg_copy_from_bbox, METH_VARARGS, NULL},
  524. {"restore_region", (PyCFunction)PyRendererAgg_restore_region, METH_VARARGS, NULL},
  525. {NULL}
  526. };
  527. static PyBufferProcs buffer_procs;
  528. buffer_procs.bf_getbuffer = (getbufferproc)PyRendererAgg_get_buffer;
  529. PyRendererAggType.tp_name = "matplotlib.backends._backend_agg.RendererAgg";
  530. PyRendererAggType.tp_basicsize = sizeof(PyRendererAgg);
  531. PyRendererAggType.tp_dealloc = (destructor)PyRendererAgg_dealloc;
  532. PyRendererAggType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
  533. PyRendererAggType.tp_methods = methods;
  534. PyRendererAggType.tp_init = (initproc)PyRendererAgg_init;
  535. PyRendererAggType.tp_new = PyRendererAgg_new;
  536. PyRendererAggType.tp_as_buffer = &buffer_procs;
  537. return &PyRendererAggType;
  538. }
  539. static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "_backend_agg" };
  540. PyMODINIT_FUNC PyInit__backend_agg(void)
  541. {
  542. import_array();
  543. PyObject *m;
  544. if (!(m = PyModule_Create(&moduledef))
  545. || prepare_and_add_type(PyRendererAgg_init_type(), m)
  546. // BufferRegion is not constructible from Python, thus not added to the module.
  547. || PyType_Ready(PyBufferRegion_init_type())
  548. ) {
  549. Py_XDECREF(m);
  550. return NULL;
  551. }
  552. return m;
  553. }