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

Skip to content

Commit 377dba4

Browse files
committed
Drop alpha channel when saving comparison failure diff image.
We drop (for the better or the worse) the alpha channel when *comparing* the images (in `compare_images`), but not when saving; thus, a comparison failure where additionally the reference has no alpha but the generated image has an alpha channel would so far raise a spurious "image sizes do not match" when trying to save the diff image, rather than actually saving the diff image as expected. Noted while running the Matplotlib test suite with mplcairo.
1 parent 3719994 commit 377dba4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/matplotlib/testing/compare.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,9 @@ def compare_images(expected, actual, tol, in_decorator=False):
422422

423423

424424
def save_diff_image(expected, actual, output):
425-
expectedImage = _png.read_png(expected)
426-
actualImage = _png.read_png(actual)
425+
# Drop alpha channels, similarly to compare_images.
426+
expectedImage = _png.read_png(expected)[..., :3]
427+
actualImage = _png.read_png(actual)[..., :3]
427428
actualImage, expectedImage = crop_to_same(
428429
actual, actualImage, expected, expectedImage)
429430
expectedImage = np.array(expectedImage).astype(float)

0 commit comments

Comments
 (0)