Skip to content

Commit

Permalink
BUG Raise exception for invalid input
Browse files Browse the repository at this point in the history
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
  • Loading branch information
luispedro committed Nov 30, 2013
1 parent b6a0c7e commit eb2480a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/matplotlib/cm.py
Expand Up @@ -248,6 +248,8 @@ def to_rgba(self, x, alpha=None, bytes=False):
xx = x
else:
raise ValueError("third dimension must be 3 or 4")
if xx.dtype != np.uint8 and xx.max() > 1:
raise ValueError("image must be either uint8 or in the 0..1 range")
if bytes and xx.dtype != np.uint8:
xx = (xx * 255).astype(np.uint8)
if not bytes and xx.dtype == np.uint8:
Expand Down

0 comments on commit eb2480a

Please sign in to comment.