Skip to content

Commit

Permalink
Fix for issue matplotlib#2963
Browse files Browse the repository at this point in the history
Image::resize will now raise a runtime error if the user passes in an invalid width or height.
BboxImage.make_image will now ensure that the width and height it passes to Image::resize are positive or zero.
BboxImage.draw now calculates the bottom left corner of its Bbox, rather than using the "first" corner of its Bbox.
  • Loading branch information
solvents committed Apr 26, 2014
1 parent a809ef9 commit 9a7991d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,8 @@ def make_image(self, renderer, magnification=1.0):
im.set_resample(self._resample)

l, b, r, t = self.get_window_extent(renderer).extents # bbox.extents
widthDisplay = round(r) - round(l)
heightDisplay = round(t) - round(b)
widthDisplay = abs(round(r) - round(l))
heightDisplay = abs(round(t) - round(b))
widthDisplay *= magnification
heightDisplay *= magnification

Expand Down Expand Up @@ -1183,11 +1183,14 @@ def draw(self, renderer, *args, **kwargs):
# todo: we should be able to do some cacheing here
image_mag = renderer.get_image_magnification()
im = self.make_image(renderer, image_mag)
l, b, r, t = self.get_window_extent(renderer).extents
x0, y0, x1, y1 = self.get_window_extent(renderer).extents
gc = renderer.new_gc()
self._set_gc_clip(gc)
gc.set_alpha(self.get_alpha())
#gc.set_clip_path(self.get_clip_path())

l = np.min([x0, x1])
b = np.min([y0, y1])
renderer.draw_image(gc, round(l), round(b), im)
gc.restore()

Expand Down
6 changes: 6 additions & 0 deletions src/_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ Image::resize(const Py::Tuple& args, const Py::Dict& kwargs)
int numcols = Py::Int(args[0]);
int numrows = Py::Int(args[1]);

if (numcols < 0 || numrows < 0)
{
throw Py::RuntimeError(
"Width and height must have non-negative values");
}

colsOut = numcols;
rowsOut = numrows;

Expand Down

0 comments on commit 9a7991d

Please sign in to comment.