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

Appearance settings

Commit 5c16eca

Browse filesBrowse files
committed
Use numpy.take instead of C-level manipulations for tostring_argb etc.
1 parent 54cd9ce commit 5c16eca
Copy full SHA for 5c16eca

File tree

Expand file treeCollapse file tree

4 files changed

+5
-64
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+5
-64
lines changed

‎lib/matplotlib/backends/backend_agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_agg.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ def points_to_pixels(self, points):
265265
"""
266266
return points * self.dpi / 72
267267

268-
def tostring_rgb(self):
269-
return self._renderer.tostring_rgb()
268+
def buffer_rgba(self):
269+
return memoryview(self._renderer)
270270

271271
def tostring_argb(self):
272-
return self._renderer.tostring_argb()
272+
return np.asarray(self._renderer).take([3, 0, 1, 2], axis=2).tobytes()
273273

274-
def buffer_rgba(self):
275-
return memoryview(self._renderer)
274+
def tostring_rgb(self):
275+
return np.asarray(self._renderer).take([0, 1, 2], axis=2).tobytes()
276276

277277
def clear(self):
278278
self._renderer.clear()

‎src/_backend_agg.cpp

Copy file name to clipboardExpand all lines: src/_backend_agg.cpp
-23Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -156,29 +156,6 @@ bool RendererAgg::render_clippath(py::PathIterator &clippath,
156156
return has_clippath;
157157
}
158158

159-
void RendererAgg::tostring_rgb(uint8_t *buf)
160-
{
161-
// "Return the rendered buffer as an RGB string"
162-
163-
int row_len = width * 3;
164-
165-
agg::rendering_buffer renderingBufferTmp;
166-
renderingBufferTmp.attach(buf, width, height, row_len);
167-
168-
agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_rgb24());
169-
}
170-
171-
void RendererAgg::tostring_argb(uint8_t *buf)
172-
{
173-
//"Return the rendered buffer as an RGB string";
174-
175-
int row_len = width * 4;
176-
177-
agg::rendering_buffer renderingBufferTmp;
178-
renderingBufferTmp.attach(buf, width, height, row_len);
179-
agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_argb32());
180-
}
181-
182159
agg::rect_i RendererAgg::get_content_extents()
183160
{
184161
agg::rect_i r(width, height, 0, 0);

‎src/_backend_agg.h

Copy file name to clipboardExpand all lines: src/_backend_agg.h
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ class RendererAgg
203203
ColorArray &colors,
204204
agg::trans_affine &trans);
205205

206-
void tostring_rgb(uint8_t *buf);
207-
void tostring_argb(uint8_t *buf);
208206
agg::rect_i get_content_extents();
209207
void clear();
210208

‎src/_backend_agg_wrapper.cpp

Copy file name to clipboardExpand all lines: src/_backend_agg_wrapper.cpp
-34Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -525,38 +525,6 @@ PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args, PyObje
525525
Py_RETURN_NONE;
526526
}
527527

528-
static PyObject *PyRendererAgg_tostring_rgb(PyRendererAgg *self, PyObject *args, PyObject *kwds)
529-
{
530-
PyObject *buffobj = NULL;
531-
532-
buffobj = PyBytes_FromStringAndSize(NULL, self->x->get_width() * self->x->get_height() * 3);
533-
if (buffobj == NULL) {
534-
return NULL;
535-
}
536-
537-
CALL_CPP_CLEANUP("tostring_rgb",
538-
(self->x->tostring_rgb((uint8_t *)PyBytes_AS_STRING(buffobj))),
539-
Py_DECREF(buffobj));
540-
541-
return buffobj;
542-
}
543-
544-
static PyObject *PyRendererAgg_tostring_argb(PyRendererAgg *self, PyObject *args, PyObject *kwds)
545-
{
546-
PyObject *buffobj = NULL;
547-
548-
buffobj = PyBytes_FromStringAndSize(NULL, self->x->get_width() * self->x->get_height() * 4);
549-
if (buffobj == NULL) {
550-
return NULL;
551-
}
552-
553-
CALL_CPP_CLEANUP("tostring_argb",
554-
(self->x->tostring_argb((uint8_t *)PyBytes_AS_STRING(buffobj))),
555-
Py_DECREF(buffobj));
556-
557-
return buffobj;
558-
}
559-
560528
static PyObject *
561529
PyRendererAgg_get_content_extents(PyRendererAgg *self, PyObject *args, PyObject *kwds)
562530
{
@@ -664,8 +632,6 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)
664632
{"draw_gouraud_triangle", (PyCFunction)PyRendererAgg_draw_gouraud_triangle, METH_VARARGS, NULL},
665633
{"draw_gouraud_triangles", (PyCFunction)PyRendererAgg_draw_gouraud_triangles, METH_VARARGS, NULL},
666634

667-
{"tostring_rgb", (PyCFunction)PyRendererAgg_tostring_rgb, METH_NOARGS, NULL},
668-
{"tostring_argb", (PyCFunction)PyRendererAgg_tostring_argb, METH_NOARGS, NULL},
669635
{"get_content_extents", (PyCFunction)PyRendererAgg_get_content_extents, METH_NOARGS, NULL},
670636
{"buffer_rgba", (PyCFunction)PyRendererAgg_buffer_rgba, METH_NOARGS, NULL},
671637
{"clear", (PyCFunction)PyRendererAgg_clear, METH_NOARGS, NULL},

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.