Skip to content

Commit 3b7d1bb

Browse files
committed
Agg backend shouldn't do its own image interp
1 parent cf11aea commit 3b7d1bb

File tree

3 files changed

+20
-69
lines changed

3 files changed

+20
-69
lines changed

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def option_scale_image(self):
321321
"""
322322
agg backend support arbitrary scaling of image.
323323
"""
324-
return True
324+
return False
325325

326326
def restore_region(self, region, bbox=None, xy=None):
327327
"""
@@ -389,28 +389,22 @@ def post_processing(image, dpi):
389389
# For agg_filter to work, the rendere's method need
390390
# to overridden in the class. See draw_markers, and draw_path_collections
391391

392-
from matplotlib._image import fromarray
393-
394392
width, height = int(self.width), int(self.height)
395393

396394
buffer, bounds = self.tostring_rgba_minimized()
397395

398396
l, b, w, h = bounds
399397

400-
401398
self._renderer = self._filter_renderers.pop()
402399
self._update_methods()
403400

404401
if w > 0 and h > 0:
405402
img = np.fromstring(buffer, np.uint8)
406403
img, ox, oy = post_processing(img.reshape((h, w, 4)) / 255.,
407404
self.dpi)
408-
image = fromarray(img, 1)
409-
410405
gc = self.new_gc()
411-
self._renderer.draw_image(gc,
412-
l+ox, height - b - h +oy,
413-
image)
406+
self._renderer.draw_image(
407+
gc, l + ox, height - b - h + oy, img)
414408

415409

416410
def new_figure_manager(num, *args, **kwargs):

src/_backend_agg.h

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,7 @@ class RendererAgg
158158
void draw_image(GCAgg &gc,
159159
double x,
160160
double y,
161-
ImageArray &image,
162-
double w,
163-
double h,
164-
agg::trans_affine trans,
165-
bool resize);
161+
ImageArray &image);
166162

167163
template <class PathGenerator,
168164
class TransformArray,
@@ -832,11 +828,7 @@ template <class ImageArray>
832828
inline void RendererAgg::draw_image(GCAgg &gc,
833829
double x,
834830
double y,
835-
ImageArray &image,
836-
double w,
837-
double h,
838-
agg::trans_affine trans,
839-
bool resize)
831+
ImageArray &image)
840832
{
841833
double alpha = gc.alpha;
842834

@@ -850,21 +842,11 @@ inline void RendererAgg::draw_image(GCAgg &gc,
850842
image.data(), (unsigned)image.dim(1), (unsigned)image.dim(0), -(int)image.dim(1) * 4);
851843
pixfmt pixf(buffer);
852844

853-
if (resize | has_clippath) {
845+
if (has_clippath) {
854846
agg::trans_affine mtx;
855847
agg::path_storage rect;
856848

857-
if (resize) {
858-
mtx *= agg::trans_affine_scaling(1, -1);
859-
mtx *= agg::trans_affine_translation(0, image.dim(0));
860-
mtx *= agg::trans_affine_scaling(w / (image.dim(1)), h / (image.dim(0)));
861-
mtx *= agg::trans_affine_translation(x, y);
862-
mtx *= trans;
863-
mtx *= agg::trans_affine_scaling(1.0, -1.0);
864-
mtx *= agg::trans_affine_translation(0.0, (double)height);
865-
} else {
866-
mtx *= agg::trans_affine_translation((int)x, (int)(height - (y + image.dim(0))));
867-
}
849+
mtx *= agg::trans_affine_translation((int)x, (int)(height - (y + image.dim(0))));
868850

869851
rect.move_to(0, 0);
870852
rect.line_to(image.dim(1), 0);
@@ -891,30 +873,17 @@ inline void RendererAgg::draw_image(GCAgg &gc,
891873
span_conv_alpha conv_alpha(alpha);
892874
span_conv spans(image_span_generator, conv_alpha);
893875

894-
if (has_clippath) {
895-
typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
896-
typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
897-
typedef agg::renderer_scanline_aa<amask_ren_type, color_span_alloc_type, span_conv>
876+
typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
877+
typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
878+
typedef agg::renderer_scanline_aa<amask_ren_type, color_span_alloc_type, span_conv>
898879
renderer_type_alpha;
899880

900-
pixfmt_amask_type pfa(pixFmt, alphaMask);
901-
amask_ren_type r(pfa);
902-
renderer_type_alpha ri(r, sa, spans);
903-
904-
theRasterizer.add_path(rect2);
905-
agg::render_scanlines(theRasterizer, scanlineAlphaMask, ri);
906-
} else {
907-
typedef agg::renderer_base<pixfmt> ren_type;
908-
typedef agg::renderer_scanline_aa<ren_type, color_span_alloc_type, span_conv>
909-
renderer_type;
910-
911-
ren_type r(pixFmt);
912-
renderer_type ri(r, sa, spans);
913-
914-
theRasterizer.add_path(rect2);
915-
agg::render_scanlines(theRasterizer, slineP8, ri);
916-
}
881+
pixfmt_amask_type pfa(pixFmt, alphaMask);
882+
amask_ren_type r(pfa);
883+
renderer_type_alpha ri(r, sa, spans);
917884

885+
theRasterizer.add_path(rect2);
886+
agg::render_scanlines(theRasterizer, scanlineAlphaMask, ri);
918887
} else {
919888
set_clipbox(gc.cliprect, rendererBase);
920889
rendererBase.blend_from(

src/_backend_agg_wrapper.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -284,34 +284,22 @@ static PyObject *PyRendererAgg_draw_image(PyRendererAgg *self, PyObject *args, P
284284
double x;
285285
double y;
286286
numpy::array_view<agg::int8u, 3> image;
287-
double w = 0;
288-
double h = 0;
289-
agg::trans_affine trans;
290-
bool resize = false;
291287

292288
if (!PyArg_ParseTuple(args,
293-
"O&ddO&|ddO&:draw_image",
289+
"O&ddO&:draw_image",
294290
&convert_gcagg,
295291
&gc,
296292
&x,
297293
&y,
298294
&image.converter_contiguous,
299-
&image,
300-
&w,
301-
&h,
302-
&convert_trans_affine,
303-
&trans)) {
295+
&image)) {
304296
return NULL;
305297
}
306298

307-
if (PyTuple_Size(args) == 4) {
308-
x = mpl_round(x);
309-
y = mpl_round(y);
310-
} else {
311-
resize = true;
312-
}
299+
x = mpl_round(x);
300+
y = mpl_round(y);
313301

314-
CALL_CPP("draw_image", (self->x->draw_image(gc, x, y, image, w, h, trans, resize)));
302+
CALL_CPP("draw_image", (self->x->draw_image(gc, x, y, image)));
315303

316304
Py_RETURN_NONE;
317305
}

0 commit comments

Comments
 (0)