From 944c36870984aaf5914eb703500199f4fcc43e71 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 22 Jul 2018 15:06:45 +0200 Subject: [PATCH] Small cleanups to backend_agg. - The private _get_hinting_flag is unused. - Despite what the comment says, draw_markers and draw_path_collection can certainly be defined in update_methods (the comment came in at the same time as demo_agg_filter.py in b5f348d, which still runs fine after this patch). - Remove the unused tostring_bgra (which is not publically exposed in the wrapper Python-level RendererAgg class -- the C-level class is not publically accessible). - Small style fixes. --- .flake8 | 2 +- lib/matplotlib/backends/backend_agg.py | 33 ++++++-------------------- src/_backend_agg.cpp | 12 ---------- src/_backend_agg.h | 1 - src/_backend_agg_wrapper.cpp | 19 +-------------- 5 files changed, 9 insertions(+), 58 deletions(-) diff --git a/.flake8 b/.flake8 index d56c6c1858dd..eb05e4a81d8c 100644 --- a/.flake8 +++ b/.flake8 @@ -32,7 +32,7 @@ per-file-ignores = matplotlib/_mathtext_data.py: E203, E261 matplotlib/backend_bases.py: E225 matplotlib/backends/_backend_tk.py: E203, E222, E225, E231, E271, E301, E303, E401, E501, E701 - matplotlib/backends/backend_agg.py: E261, E302, E303, E701 + matplotlib/backends/backend_agg.py: E261, E302, E701 matplotlib/backends/backend_cairo.py: E203, E221, E261, E303, E402, E711 matplotlib/backends/backend_gtk3.py: E203, E221, E222, E225, E251, E261, E501 matplotlib/backends/backend_macosx.py: E231, E261 diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index ca7a44700bcd..df142228b842 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -100,25 +100,13 @@ def __getstate__(self): def __setstate__(self, state): self.__init__(state['width'], state['height'], state['dpi']) - def _get_hinting_flag(self): - if rcParams['text.hinting']: - return LOAD_FORCE_AUTOHINT - else: - return LOAD_NO_HINTING - - # for filtering to work with rasterization, methods needs to be wrapped. - # maybe there is better way to do it. - def draw_markers(self, *kl, **kw): - return self._renderer.draw_markers(*kl, **kw) - - def draw_path_collection(self, *kl, **kw): - return self._renderer.draw_path_collection(*kl, **kw) - def _update_methods(self): - self.draw_quad_mesh = self._renderer.draw_quad_mesh self.draw_gouraud_triangle = self._renderer.draw_gouraud_triangle self.draw_gouraud_triangles = self._renderer.draw_gouraud_triangles self.draw_image = self._renderer.draw_image + self.draw_markers = self._renderer.draw_markers + self.draw_path_collection = self._renderer.draw_path_collection + self.draw_quad_mesh = self._renderer.draw_quad_mesh self.copy_from_bbox = self._renderer.copy_from_bbox self.get_content_extents = self._renderer.get_content_extents @@ -163,7 +151,6 @@ def draw_path(self, gc, path, transform, rgbFace=None): raise OverflowError("Exceeded cell block limit (set " "'agg.path.chunksize' rcparam)") - def draw_mathtext(self, gc, x, y, s, prop, angle): """ Draw the math text using matplotlib.mathtext @@ -260,7 +247,7 @@ def get_canvas_width_height(self): def _get_agg_font(self, prop): """ - Get the font for text instance t, cacheing for efficiency + Get the font for text instance t, caching for efficiency """ fname = findfont(prop) font = get_font(fname) @@ -276,7 +263,7 @@ def points_to_pixels(self, points): convert point measures to pixes using dpi and the pixels per inch of the display """ - return points*self.dpi/72.0 + return points * self.dpi / 72 def tostring_rgb(self): return self._renderer.tostring_rgb() @@ -364,14 +351,9 @@ def post_processing(image, dpi): post_processing is plotted (using draw_image) on it. """ - # WARNING: For agg_filter to work, the renderer's method need to - # overridden in the class. See draw_markers and draw_path_collections. - width, height = int(self.width), int(self.height) - buffer, bounds = self.tostring_rgba_minimized() - - l, b, w, h = bounds + buffer, (l, b, w, h) = self.tostring_rgba_minimized() self._renderer = self._filter_renderers.pop() self._update_methods() @@ -384,8 +366,7 @@ def post_processing(image, dpi): if img.dtype.kind == 'f': img = np.asarray(img * 255., np.uint8) img = img[::-1] - self._renderer.draw_image( - gc, l + ox, height - b - h + oy, img) + self._renderer.draw_image(gc, l + ox, height - b - h + oy, img) class FigureCanvasAgg(FigureCanvasBase): diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index 9cb34dca235b..6d0f90400913 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -179,18 +179,6 @@ void RendererAgg::tostring_argb(uint8_t *buf) agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_argb32()); } -void RendererAgg::tostring_bgra(uint8_t *buf) -{ - //"Return the rendered buffer as an RGB string"; - - int row_len = width * 4; - - agg::rendering_buffer renderingBufferTmp; - renderingBufferTmp.attach(buf, width, height, row_len); - - agg::color_conv(&renderingBufferTmp, &renderingBuffer, agg::color_conv_rgba32_to_bgra32()); -} - agg::rect_i RendererAgg::get_content_extents() { agg::rect_i r(width, height, 0, 0); diff --git a/src/_backend_agg.h b/src/_backend_agg.h index d4b85633e0fe..835302ca5719 100644 --- a/src/_backend_agg.h +++ b/src/_backend_agg.h @@ -205,7 +205,6 @@ class RendererAgg void tostring_rgb(uint8_t *buf); void tostring_argb(uint8_t *buf); - void tostring_bgra(uint8_t *buf); agg::rect_i get_content_extents(); void clear(); diff --git a/src/_backend_agg_wrapper.cpp b/src/_backend_agg_wrapper.cpp index 8bd3cea9a037..3c26a8b67cde 100644 --- a/src/_backend_agg_wrapper.cpp +++ b/src/_backend_agg_wrapper.cpp @@ -557,22 +557,6 @@ static PyObject *PyRendererAgg_tostring_argb(PyRendererAgg *self, PyObject *args return buffobj; } -static PyObject *PyRendererAgg_tostring_bgra(PyRendererAgg *self, PyObject *args, PyObject *kwds) -{ - PyObject *buffobj = NULL; - - buffobj = PyBytes_FromStringAndSize(NULL, self->x->get_width() * self->x->get_height() * 4); - if (buffobj == NULL) { - return NULL; - } - - CALL_CPP_CLEANUP("to_string_bgra", - (self->x->tostring_bgra((uint8_t *)PyBytes_AS_STRING(buffobj))), - Py_DECREF(buffobj)); - - return buffobj; -} - static PyObject * PyRendererAgg_get_content_extents(PyRendererAgg *self, PyObject *args, PyObject *kwds) { @@ -658,7 +642,7 @@ static PyObject *PyRendererAgg_restore_region(PyRendererAgg *self, PyObject *arg } if (PySequence_Size(args) == 1) { - CALL_CPP("restore_region", (self->x->restore_region(*(regobj->x)))); + CALL_CPP("restore_region", self->x->restore_region(*(regobj->x))); } else { CALL_CPP("restore_region", self->x->restore_region(*(regobj->x), xx1, yy1, xx2, yy2, x, y)); } @@ -682,7 +666,6 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type) {"tostring_rgb", (PyCFunction)PyRendererAgg_tostring_rgb, METH_NOARGS, NULL}, {"tostring_argb", (PyCFunction)PyRendererAgg_tostring_argb, METH_NOARGS, NULL}, - {"tostring_bgra", (PyCFunction)PyRendererAgg_tostring_bgra, METH_NOARGS, NULL}, {"get_content_extents", (PyCFunction)PyRendererAgg_get_content_extents, METH_NOARGS, NULL}, {"buffer_rgba", (PyCFunction)PyRendererAgg_buffer_rgba, METH_NOARGS, NULL}, {"clear", (PyCFunction)PyRendererAgg_clear, METH_NOARGS, NULL},