Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e010538

Browse files
authored
Merge pull request #11734 from anntzer/aggcleanup
Small cleanups to backend_agg.
2 parents c660b33 + 944c368 commit e010538

File tree

5 files changed

+9
-58
lines changed

5 files changed

+9
-58
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ per-file-ignores =
3232
matplotlib/_mathtext_data.py: E203, E261
3333
matplotlib/backend_bases.py: E225
3434
matplotlib/backends/_backend_tk.py: E203, E222, E225, E231, E271, E301, E303, E401, E501, E701
35-
matplotlib/backends/backend_agg.py: E261, E302, E303, E701
35+
matplotlib/backends/backend_agg.py: E261, E302, E701
3636
matplotlib/backends/backend_cairo.py: E203, E221, E261, E303, E402, E711
3737
matplotlib/backends/backend_gtk3.py: E203, E221, E222, E225, E251, E261, E501
3838
matplotlib/backends/backend_macosx.py: E231, E261

lib/matplotlib/backends/backend_agg.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,13 @@ def __getstate__(self):
100100
def __setstate__(self, state):
101101
self.__init__(state['width'], state['height'], state['dpi'])
102102

103-
def _get_hinting_flag(self):
104-
if rcParams['text.hinting']:
105-
return LOAD_FORCE_AUTOHINT
106-
else:
107-
return LOAD_NO_HINTING
108-
109-
# for filtering to work with rasterization, methods needs to be wrapped.
110-
# maybe there is better way to do it.
111-
def draw_markers(self, *kl, **kw):
112-
return self._renderer.draw_markers(*kl, **kw)
113-
114-
def draw_path_collection(self, *kl, **kw):
115-
return self._renderer.draw_path_collection(*kl, **kw)
116-
117103
def _update_methods(self):
118-
self.draw_quad_mesh = self._renderer.draw_quad_mesh
119104
self.draw_gouraud_triangle = self._renderer.draw_gouraud_triangle
120105
self.draw_gouraud_triangles = self._renderer.draw_gouraud_triangles
121106
self.draw_image = self._renderer.draw_image
107+
self.draw_markers = self._renderer.draw_markers
108+
self.draw_path_collection = self._renderer.draw_path_collection
109+
self.draw_quad_mesh = self._renderer.draw_quad_mesh
122110
self.copy_from_bbox = self._renderer.copy_from_bbox
123111
self.get_content_extents = self._renderer.get_content_extents
124112

@@ -163,7 +151,6 @@ def draw_path(self, gc, path, transform, rgbFace=None):
163151
raise OverflowError("Exceeded cell block limit (set "
164152
"'agg.path.chunksize' rcparam)")
165153

166-
167154
def draw_mathtext(self, gc, x, y, s, prop, angle):
168155
"""
169156
Draw the math text using matplotlib.mathtext
@@ -260,7 +247,7 @@ def get_canvas_width_height(self):
260247

261248
def _get_agg_font(self, prop):
262249
"""
263-
Get the font for text instance t, cacheing for efficiency
250+
Get the font for text instance t, caching for efficiency
264251
"""
265252
fname = findfont(prop)
266253
font = get_font(fname)
@@ -276,7 +263,7 @@ def points_to_pixels(self, points):
276263
convert point measures to pixes using dpi and the pixels per
277264
inch of the display
278265
"""
279-
return points*self.dpi/72.0
266+
return points * self.dpi / 72
280267

281268
def tostring_rgb(self):
282269
return self._renderer.tostring_rgb()
@@ -364,14 +351,9 @@ def post_processing(image, dpi):
364351
post_processing is plotted (using draw_image) on it.
365352
"""
366353

367-
# WARNING: For agg_filter to work, the renderer's method need to
368-
# overridden in the class. See draw_markers and draw_path_collections.
369-
370354
width, height = int(self.width), int(self.height)
371355

372-
buffer, bounds = self.tostring_rgba_minimized()
373-
374-
l, b, w, h = bounds
356+
buffer, (l, b, w, h) = self.tostring_rgba_minimized()
375357

376358
self._renderer = self._filter_renderers.pop()
377359
self._update_methods()
@@ -384,8 +366,7 @@ def post_processing(image, dpi):
384366
if img.dtype.kind == 'f':
385367
img = np.asarray(img * 255., np.uint8)
386368
img = img[::-1]
387-
self._renderer.draw_image(
388-
gc, l + ox, height - b - h + oy, img)
369+
self._renderer.draw_image(gc, l + ox, height - b - h + oy, img)
389370

390371

391372
class FigureCanvasAgg(FigureCanvasBase):

src/_backend_agg.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,6 @@ void RendererAgg::tostring_argb(uint8_t *buf)
179179
agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_argb32());
180180
}
181181

182-
void RendererAgg::tostring_bgra(uint8_t *buf)
183-
{
184-
//"Return the rendered buffer as an RGB string";
185-
186-
int row_len = width * 4;
187-
188-
agg::rendering_buffer renderingBufferTmp;
189-
renderingBufferTmp.attach(buf, width, height, row_len);
190-
191-
agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_bgra32());
192-
}
193-
194182
agg::rect_i RendererAgg::get_content_extents()
195183
{
196184
agg::rect_i r(width, height, 0, 0);

src/_backend_agg.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ class RendererAgg
205205

206206
void tostring_rgb(uint8_t *buf);
207207
void tostring_argb(uint8_t *buf);
208-
void tostring_bgra(uint8_t *buf);
209208
agg::rect_i get_content_extents();
210209
void clear();
211210

src/_backend_agg_wrapper.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -557,22 +557,6 @@ static PyObject *PyRendererAgg_tostring_argb(PyRendererAgg *self, PyObject *args
557557
return buffobj;
558558
}
559559

560-
static PyObject *PyRendererAgg_tostring_bgra(PyRendererAgg *self, PyObject *args, PyObject *kwds)
561-
{
562-
PyObject *buffobj = NULL;
563-
564-
buffobj = PyBytes_FromStringAndSize(NULL, self->x->get_width() * self->x->get_height() * 4);
565-
if (buffobj == NULL) {
566-
return NULL;
567-
}
568-
569-
CALL_CPP_CLEANUP("to_string_bgra",
570-
(self->x->tostring_bgra((uint8_t *)PyBytes_AS_STRING(buffobj))),
571-
Py_DECREF(buffobj));
572-
573-
return buffobj;
574-
}
575-
576560
static PyObject *
577561
PyRendererAgg_get_content_extents(PyRendererAgg *self, PyObject *args, PyObject *kwds)
578562
{
@@ -658,7 +642,7 @@ static PyObject *PyRendererAgg_restore_region(PyRendererAgg *self, PyObject *arg
658642
}
659643

660644
if (PySequence_Size(args) == 1) {
661-
CALL_CPP("restore_region", (self->x->restore_region(*(regobj->x))));
645+
CALL_CPP("restore_region", self->x->restore_region(*(regobj->x)));
662646
} else {
663647
CALL_CPP("restore_region", self->x->restore_region(*(regobj->x), xx1, yy1, xx2, yy2, x, y));
664648
}
@@ -682,7 +666,6 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)
682666

683667
{"tostring_rgb", (PyCFunction)PyRendererAgg_tostring_rgb, METH_NOARGS, NULL},
684668
{"tostring_argb", (PyCFunction)PyRendererAgg_tostring_argb, METH_NOARGS, NULL},
685-
{"tostring_bgra", (PyCFunction)PyRendererAgg_tostring_bgra, METH_NOARGS, NULL},
686669
{"get_content_extents", (PyCFunction)PyRendererAgg_get_content_extents, METH_NOARGS, NULL},
687670
{"buffer_rgba", (PyCFunction)PyRendererAgg_buffer_rgba, METH_NOARGS, NULL},
688671
{"clear", (PyCFunction)PyRendererAgg_clear, METH_NOARGS, NULL},

0 commit comments

Comments
 (0)