10BC0 image: modify alpha premultiply to work with modified to_rgba · matplotlib/matplotlib@95e6fcd · GitHub
[go: up one dir, main page]

Skip to content

Commit 95e6fcd

Browse files
committed
image: modify alpha premultiply to work with modified to_rgba
The earlier version of the premultiplication step did not work with numpy 2, and required additional dtype conversion steps in the common case of a colormapped image.
1 parent cef11c7 commit 95e6fcd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/image.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,14 @@ def _get_unsampled_image(self, A, image_extents, viewlim):
199199
im.is_grayscale = False
200200
else:
201201
if self._rgbacache is None:
202-
x = self.to_rgba(self._A, bytes=True)
202+
x = self.to_rgba(self._A, bytes=False)
203+
# Avoid side effects: to_rgba can return its argument
204+
# unchanged.
205+
if np.may_share_memory(x, self._A):
206+
x = x.copy()
203207
# premultiply the colors
204-
x[...,0:3] *= x[...,3:4] / 255.0
208+
x[...,0:3] *= x[...,3:4]
209+
x = (x * 255).astype(np.uint8)
205210
self._rgbacache = x
206211
else:
207212
x = self._rgbacache

0 commit comments

Comments
 (0)
0