Skip to content

Commit 50b6ed3

Browse files
committed
Revert "Restrict resampling in premultiplied alpha space to only when alpha is not constant"
This reverts commit 269fe6d.
1 parent c752389 commit 50b6ed3

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

‎lib/matplotlib/image.py‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -510,25 +510,16 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
510510
A = np.dstack([A, np.full(A.shape[:2], alpha, np.float32)])
511511
else: # or apply scalar alpha to existing alpha channel
512512
post_apply_alpha = True
513-
# Premultiply alpha only if the alpha channel is not constant
514-
if np.any(A[..., 3:] != A[0, 0, 3]):
515-
# Resample in premultiplied alpha space. (TODO: Consider
516-
# implementing premultiplied-space resampling in
517-
# span_image_resample_rgba_affine::generate?)
518-
if float_rgba_in and np.ndim(alpha) == 0 and np.any(A[..., 3] < 1):
519-
# Do not modify original RGBA input
520-
A = A.copy()
521-
A[..., :3] *= A[..., 3:]
522-
res = _resample(self, A, out_shape, t)
523-
# This division may distort colors at the edges of the image
524-
np.divide(res[..., :3], res[..., 3:], out=res[..., :3],
525-
where=res[..., 3:] != 0)
526-
else:
527-
# Even though the input alpha channel is constant,
528-
# be aware that the output alpha channel may not be constant
529-
# because the resampler may adjust the alpha to antialias
530-
# the image edges
531-
res = _resample(self, A, out_shape, t)
513+
# Resample in premultiplied alpha space. (TODO: Consider
514+
# implementing premultiplied-space resampling in
515+
# span_image_resample_rgba_affine::generate?)
516+
if float_rgba_in and np.ndim(alpha) == 0 and np.any(A[..., 3] < 1):
517+
# Do not modify original RGBA input
518+
A = A.copy()
519+
A[..., :3] *= A[..., 3:]
520+
res = _resample(self, A, out_shape, t)
521+
np.divide(res[..., :3], res[..., 3:], out=res[..., :3],
522+
where=res[..., 3:] != 0)
532523
if post_apply_alpha:
533524
res[..., 3] *= alpha
534525

0 commit comments

Comments
 (0)