BUG: Correctly handle images with an alpha channel

Bug caught by Zachary Pincus on scipy-user.
This commit is contained in:
Luis Pedro Coelho
2010-11-12 09:44:58 -05:00
parent 082798d5f8
commit ff02f4ce9d
+11 -4
View File
@@ -320,10 +320,17 @@ def _array_from_bitmap(bitmap):
return arr[..., ::-1].T
if len(shape) == 3 and _FI.FreeImage_IsLittleEndian() and \
dtype.type == numpy.uint8:
b = array[0]
g = array[1]
r = array[2]
return numpy.dstack( (n(r), n(g), n(b)) )
b = n(array[0])
g = n(array[1])
r = n(array[2])
if shape[0] == 3:
return numpy.dstack( (r, g, b) )
elif shape[0] == 4:
a = n(array[3])
return numpy.dstack( (r, g, b, a) )
else:
raise ValueError('Cannot handle images of shape %s' % shape)
# We need to copy because array does *not* own its memory
# after bitmap is freed.
return n(array).copy()