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

Skip to content

Small cleanups to backend_agg. #11734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 7 additions & 26 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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):
Expand Down
12 changes: 0 additions & 12 deletions src/_backend_agg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
19 changes: 1 addition & 18 deletions src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}
Expand All @@ -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},
Expand Down