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

Commitc42b587

Browse files
committed
Use numpy.take instead of C-level manipulations for tostring_argb etc.
1 parent1151b27 commitc42b587

File tree

4 files changed

+5
-64
lines changed

4 files changed

+5
-64
lines changed

‎lib/matplotlib/backends/backend_agg.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,14 @@ def points_to_pixels(self, points):
278278
"""
279279
returnpoints*self.dpi/72.0
280280

281-
deftostring_rgb(self):
282-
returnself._renderer.tostring_rgb()
281+
defbuffer_rgba(self):
282+
returnnp.asarray(self._renderer)
283283

284284
deftostring_argb(self):
285-
returnself._renderer.tostring_argb()
285+
returnnp.asarray(self._renderer).take([3,0,1,2],axis=2).tobytes()
286286

287-
defbuffer_rgba(self):
288-
returnnp.asarray(self._renderer)
287+
deftostring_rgb(self):
288+
returnnp.asarray(self._renderer).take([0,1,2],axis=2).tobytes()
289289

290290
defclear(self):
291291
self._renderer.clear()

‎src/_backend_agg.cpp‎

Lines 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-
voidRendererAgg::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-
voidRendererAgg::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
voidRendererAgg::tostring_bgra(uint8_t *buf)
183160
{
184161
//"Return the rendered buffer as an RGB string";

‎src/_backend_agg.h‎

Lines 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-
voidtostring_rgb(uint8_t *buf);
207-
voidtostring_argb(uint8_t *buf);
208206
voidtostring_bgra(uint8_t *buf);
209207
agg::rect_iget_content_extents();
210208
voidclear();

‎src/_backend_agg_wrapper.cpp‎

Lines 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-
returnNULL;
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-
returnNULL;
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 *PyRendererAgg_tostring_bgra(PyRendererAgg *self, PyObject *args, PyObject *kwds)
561529
{
562530
PyObject *buffobj =NULL;
@@ -680,8 +648,6 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)
680648
{"draw_gouraud_triangle", (PyCFunction)PyRendererAgg_draw_gouraud_triangle, METH_VARARGS,NULL},
681649
{"draw_gouraud_triangles", (PyCFunction)PyRendererAgg_draw_gouraud_triangles, METH_VARARGS,NULL},
682650

683-
{"tostring_rgb", (PyCFunction)PyRendererAgg_tostring_rgb, METH_NOARGS,NULL},
684-
{"tostring_argb", (PyCFunction)PyRendererAgg_tostring_argb, METH_NOARGS,NULL},
685651
{"tostring_bgra", (PyCFunction)PyRendererAgg_tostring_bgra, METH_NOARGS,NULL},
686652
{"get_content_extents", (PyCFunction)PyRendererAgg_get_content_extents, METH_NOARGS,NULL},
687653
{"buffer_rgba", (PyCFunction)PyRendererAgg_buffer_rgba, METH_NOARGS,NULL},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp