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

Skip to content

Image: handle images with zero columns or rows. #3102

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
Jun 1, 2014
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: 2 additions & 0 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ def _draw_unsampled_image(self, renderer, gc):
im.reset_matrix()
numrows, numcols = im.get_size()

if numrows <= 0 or numcols <= 0:
return
im.resize(numcols, numrows) # just to create im.bufOut that
# is required by backends. There
# may be better solution -JJL
Expand Down
6 changes: 3 additions & 3 deletions src/_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ 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)
if (numcols <= 0 || numrows <= 0)
{
throw Py::RuntimeError(
"Width and height must have non-negative values");
throw Py::RuntimeError(
"Width and height must have positive values");
}

colsOut = numcols;
Expand Down
6 changes: 6 additions & 0 deletions src/_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class Image : public Py::PythonExtension<Image>
inline Py::Object flipud_out(const Py::Tuple& args)
{
args.verify_length(0);
if (colsOut <= 0 || rowsOut <= 0)
{
throw Py::RuntimeError(
"Width and height must have positive values");
}

int stride = rbufOut->stride();
//std::cout << "flip before: " << rbufOut->stride() << std::endl;
rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);
Expand Down