Skip to content

Commit c3e1c1b

Browse files
committed
Directly remove the C-level get_content_extents.
1 parent 56e87ef commit c3e1c1b

File tree

3 files changed

+5
-49
lines changed

3 files changed

+5
-49
lines changed

lib/matplotlib/backends/backend_agg.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,12 @@ def _update_methods(self):
117117
self.draw_quad_mesh = self._renderer.draw_quad_mesh
118118
self.copy_from_bbox = self._renderer.copy_from_bbox
119119

120-
@cbook.deprecated("3.4") # Also needs to be removed at C-level.
120+
@cbook.deprecated("3.4")
121121
def get_content_extents(self):
122-
return self._renderer.get_content_extents()
122+
orig_img = np.asarray(self.buffer_rgba())
123+
slice_y, slice_x = cbook._get_nonzero_slices(orig_img[..., 3])
124+
return (slice_x.start, slice_y.start,
125+
slice_x.stop - slice_x.start, slice_y.stop - slice_y.start)
123126

124127
@cbook.deprecated("3.4")
125128
def tostring_rgba_minimized(self):

src/_backend_agg.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -167,41 +167,6 @@ bool RendererAgg::render_clippath(py::PathIterator &clippath,
167167
return has_clippath;
168168
}
169169

170-
agg::rect_i RendererAgg::get_content_extents()
171-
{
172-
agg::rect_i r(width, height, 0, 0);
173-
174-
// Looks at the alpha channel to find the minimum extents of the image
175-
unsigned char *pixel = pixBuffer + 3;
176-
for (int y = 0; y < (int)height; ++y) {
177-
for (int x = 0; x < (int)width; ++x) {
178-
if (*pixel) {
179-
if (x < r.x1)
180-
r.x1 = x;
181-
if (y < r.y1)
182-
r.y1 = y;
183-
if (x > r.x2)
184-
r.x2 = x;
185-
if (y > r.y2)
186-
r.y2 = y;
187-
}
188-
pixel += 4;
189-
}
190-
}
191-
192-
if (r.x1 == (int)width && r.x2 == 0) {
193-
// The buffer is completely empty.
194-
r.x1 = r.y1 = r.x2 = r.y2 = 0;
195-
} else {
196-
r.x1 = std::max(0, r.x1);
197-
r.y1 = std::max(0, r.y1);
198-
r.x2 = std::min(r.x2 + 1, (int)width);
199-
r.y2 = std::min(r.y2 + 1, (int)height);
200-
}
201-
202-
return r;
203-
}
204-
205170
void RendererAgg::clear()
206171
{
207172
//"clear the rendered buffer";

src/_backend_agg_wrapper.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -526,17 +526,6 @@ PyRendererAgg_draw_gouraud_triangles(PyRendererAgg *self, PyObject *args, PyObje
526526
Py_RETURN_NONE;
527527
}
528528

529-
static PyObject *
530-
PyRendererAgg_get_content_extents(PyRendererAgg *self, PyObject *args, PyObject *kwds)
531-
{
532-
agg::rect_i extents;
533-
534-
CALL_CPP("get_content_extents", (extents = self->x->get_content_extents()));
535-
536-
return Py_BuildValue(
537-
"iiii", extents.x1, extents.y1, extents.x2 - extents.x1, extents.y2 - extents.y1);
538-
}
539-
540529
int PyRendererAgg_get_buffer(PyRendererAgg *self, Py_buffer *buf, int flags)
541530
{
542531
Py_INCREF(self);
@@ -627,7 +616,6 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)
627616
{"draw_gouraud_triangle", (PyCFunction)PyRendererAgg_draw_gouraud_triangle, METH_VARARGS, NULL},
628617
{"draw_gouraud_triangles", (PyCFunction)PyRendererAgg_draw_gouraud_triangles, METH_VARARGS, NULL},
629618

630-
{"get_content_extents", (PyCFunction)PyRendererAgg_get_content_extents, METH_NOARGS, NULL},
631619
{"clear", (PyCFunction)PyRendererAgg_clear, METH_NOARGS, NULL},
632620

633621
{"copy_from_bbox", (PyCFunction)PyRendererAgg_copy_from_bbox, METH_VARARGS, NULL},

0 commit comments

Comments
 (0)