Skip to content
Merged
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
15 changes: 10 additions & 5 deletions lib/matplotlib/testing/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,16 @@ def calculate_rms(expected_image, actual_image):

def _load_image(path):
img = Image.open(path)
# In an RGBA image, if the smallest value in the alpha channel is 255, all
# values in it must be 255, meaning that the image is opaque. If so,
# discard the alpha channel so that it may compare equal to an RGB image.
if img.mode != "RGBA" or img.getextrema()[3][0] == 255:
img = img.convert("RGB")
if img.mode != "RGB":
Comment thread
QuLogic marked this conversation as resolved.
# If we have anything other than RGB(A) (e.g., a paletted image), convert it
# to RGBA.
if img.mode != "RGBA":
img = img.convert("RGBA")
# In an RGBA image, if the smallest value in the alpha channel is 255, all
# values in it must be 255, meaning that the image is opaque. If so, discard the
# alpha channel so that it may compare equal to an RGB image.
if img.getextrema()[3][0] == 255:
img = img.convert("RGB")
return np.asarray(img)


Expand Down
Loading