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

Skip to content

Commit 1ca2279

Browse files
committed
Fixed bug in image handling of uint8 array
svn path=/trunk/matplotlib/; revision=3165
1 parent c5b1878 commit 1ca2279

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def make_image(self, magnification=1.0):
117117
raise RuntimeError('You must first set the image array or the image attribute')
118118

119119
if self._imcache is None:
120-
if typecode(self._A) == UInt8:
120+
if typecode(self._A) == UInt8 and len(self._A.shape) == 3:
121121
im = _image.frombyte(self._A, 0)
122122
im.is_grayscale = False
123123
else:

src/_image.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,8 @@ _image_module::frombyte(const Py::Tuple& args) {
12001200
int isoutput = Py::Int(args[1]);
12011201

12021202
PyArrayObject *A = (PyArrayObject *) PyArray_ContiguousFromObject(x.ptr(), PyArray_UBYTE, 3, 3);
1203-
1203+
if (A == NULL)
1204+
throw Py::ValueError("Array must have 3 dimensions");
12041205
if (A->dimensions[2]<3 || A->dimensions[2]>4)
12051206
throw Py::ValueError("Array dimension 3 must have size 3 or 4");
12061207

@@ -1317,7 +1318,7 @@ _image_module::frombuffer(const Py::Tuple& args) {
13171318
imo->rbufIn->attach(buffer, imo->colsIn, imo->rowsIn, imo->colsIn*imo->BPP);
13181319
}
13191320

1320-
return Py::asObject(imo);
1321+
return Py::asObject(imo);
13211322
}
13221323

13231324

0 commit comments

Comments
 (0)