10000 BUG Raise exception for invalid input · andnovar/matplotlib@8433eec · GitHub
[go: up one dir, main page]

Skip to content

Commit 8433eec

Browse files
luispedroefiring
authored andcommitted
BUG Raise exception for invalid input
Arrays of non-uint8 types were assumed to be in 0..1 range. When this was not true and integer values were used, only the low-order bits were used, resulting in a mangled image. Now, an explicit exception is raised. Closes issue matplotlib#2499
1 parent 963e51d commit 8433eec

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/matplotlib/cm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True):
255255
xx = x
256256
else:
257257
raise ValueError("third dimension must be 3 or 4")
258+
if xx.dtype != np.uint8 and xx.max() > 1:
259+
raise ValueError("image must be either uint8 or in the 0..1 range")
258260
if bytes and xx.dtype != np.uint8:
259261
xx = (xx * 255).astype(np.uint8)
260262
if not bytes and xx.dtype == np.uint8:

0 commit comments

Comments
 (0)
0